Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for Yarn 2.x Berry #8301

Open
wgroeneveld opened this issue Mar 5, 2021 · 4 comments
Open

Add compatibility for Yarn 2.x Berry #8301

wgroeneveld opened this issue Mar 5, 2021 · 4 comments
Milestone

Comments

@wgroeneveld
Copy link
Contributor

Hi there,

WIthout resorting to the node-modules yarn berry plugin (see https://yarnpkg.com/features/pnp ), Hugo pipes look for a node-modules path in which dependencies are typically listed. However, Yarn 2 works slightly differently. When using yarn in conjunction with hugo extended/pipes, the following happens:

Start building sites …
Built in 366 ms
Error: Error building site: BABEL: failed to transform "js/brainbaking.js" (application/javascript): Error: Cannot find module '@babel/preset-env'
Require stack:
- /Users/wgroeneveld/development/brainbaking/babel.config.js
- /opt/homebrew/lib/node_modules/@babel/core/lib/config/files/module-types.js
- /opt/homebrew/lib/node_modules/@babel/core/lib/config/files/configuration.js
- /opt/homebrew/lib/node_modules/@babel/core/lib/config/files/index.js
- /opt/homebrew/lib/node_modules/@babel/core/lib/index.js
- /opt/homebrew/lib/node_modules/@babel/cli/lib/babel/options.js
- /opt/homebrew/lib/node_modules/@babel/cli/lib/babel/index.js
- /opt/homebrew/lib/node_modules/@babel/cli/bin/babel.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at module.exports (/Users/wgroeneveld/development/brainbaking/babel.config.js:5:4)
    at readConfigJS (/opt/homebrew/lib/node_modules/@babel/core/lib/config/files/configuration.js:212:15)
    at readConfigJS.next (<anonymous>)
    at Function.<anonymous> (/opt/homebrew/lib/node_modules/@babel/core/lib/gensync-utils/async.js:26:3)
    at Generator.next (<anonymous>)
    at step (/opt/homebrew/lib/node_modules/@babel/core/node_modules/gensync/index.js:261:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/wgroeneveld/development/brainbaking/babel.config.js',
    '/opt/homebrew/lib/node_modules/@babel/core/lib/config/files/module-types.js',
    '/opt/homebrew/lib/node_modules/@babel/core/lib/config/files/configuration.js',
    '/opt/homebrew/lib/node_modules/@babel/core/lib/config/files/index.js',
    '/opt/homebrew/lib/node_modules/@babel/core/lib/index.js',
    '/opt/homebrew/lib/node_modules/@babel/cli/lib/babel/options.js',
    '/opt/homebrew/lib/node_modules/@babel/cli/lib/babel/index.js',
    '/opt/homebrew/lib/node_modules/@babel/cli/bin/babel.js'
  ]
}
: exit status 1

This is because a yarn install command does NOT create node-modules but caches stuff locally in .yarn/cache. See above link. This can currently be "fixed" by letting Yarn produce a node-modules dir anyway, but it kind of defeats the purpose of using Yarn Berry.

It would be cool if both tools understood each other in such a way that Hugo can leverage Yarn's caching abilities.

wgroeneveld added a commit to wgroeneveld/berry that referenced this issue Mar 5, 2021
See https://gohugo.io/hugo-pipes/babel/ - without resorting to the `node-modules` plugin, sadly, Hugo pipes cannot find dependencies such as babel. It looks like this has nothing to do with `$NODE_PATH`, it is simply incompatible with Yarn Berry. I've also filed an improvement proposal under gohugo: gohugoio/hugo#8301
@wgroeneveld
Copy link
Contributor Author

wgroeneveld commented Mar 5, 2021

As a heads up for everyone, I also added hugo to the list at yarnpkg/berry#2563

babel/babel#8967 does not seem to help (using require.resolve() in babel.config.js instead of the string, or even using require).

@bep bep added Enhancement and removed Proposal labels Mar 5, 2021
@bep bep added this to the v0.82 milestone Mar 5, 2021
@bep
Copy link
Member

bep commented Mar 5, 2021

So, Hugo vs JavaScript vs node_modules isn't one thing. I see this is relates to Babel's config loading. I assume you would get the same troubles with PostCSS, maybe.

@wgroeneveld
Copy link
Contributor Author

Might be a good idea to put in the documentation for the pipes that yarn2 users use nodeLinker: node-modules in their .yarnrc.yml config for now...

@arcanis
Copy link

arcanis commented Mar 8, 2021

Error: Cannot find module '@babel/preset-env'

I don't know anything about Hugo, but this likely means that the PnP runtime isn't loaded when booting Babel. In general we would advise to 1/ add babel to the project's dependencies (locally, not globally, since they wouldn't be locked) 2/ tell Hugo to spawn it by using yarn run -B babel (instead of just babel).

merceyz pushed a commit to yarnpkg/berry that referenced this issue Mar 20, 2021
See https://gohugo.io/hugo-pipes/babel/ - without resorting to the `node-modules` plugin, sadly, Hugo pipes cannot find dependencies such as babel. It looks like this has nothing to do with `$NODE_PATH`, it is simply incompatible with Yarn Berry. I've also filed an improvement proposal under gohugo: gohugoio/hugo#8301
@bep bep modified the milestones: v0.82, v0.83 Mar 21, 2021
@bep bep modified the milestones: v0.83, v0.84 May 1, 2021
@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep removed this from the v0.91.0 milestone Dec 22, 2021
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants