resolve: v1.21.0 breaks with next.js, or without graceful-fs upgrade
Sadly, v1.21.0 seems to break babel-plugin-macros. If I pin resolve to v1.20.0, everything is fine. 2.0.0-next.3 also seems to be working. This is especially hard to debug, as its a transient dependency of many libs/plugins and a minor update. It took me quite a while to find it… 😃
Related stacktrace:
Uncaught at Object.statSync (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/@vercel/nft/index.js:1:293416)
at isDirectory (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/resolve@1.21.0/node_modules/resolve/lib/sync.js:22:23)
at loadNodeModulesSync (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/resolve@1.21.0/node_modules/resolve/lib/sync.js:191:17)
at Function.resolveSync [as sync] (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/resolve@1.21.0/node_modules/resolve/lib/sync.js:98:17)
at nodeResolvePath (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/babel-plugin-macros@3.1.0/node_modules/babel-plugin-macros/dist/index.js:62:18)
at applyMacros (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/babel-plugin-macros@3.1.0/node_modules/babel-plugin-macros/dist/index.js:203:23)
at ImportDeclaration (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/babel-plugin-macros@3.1.0/node_modules/babel-plugin-macros/dist/index.js:110:28)
at NodePath._call (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/babel/bundle.js:1890:292021)
at NodePath.call (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/babel/bundle.js:1890:291845)
at NodePath.visit (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/babel/bundle.js:1890:292796)
at processResult (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/webpack/bundle5.js:53057:19)
at <unknown> (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/webpack/bundle5.js:53159:5)
at <unknown> (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/webpack/bundle5.js:138518:11)
at <unknown> (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/webpack/bundle5.js:138370:18)
at context.callback (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/compiled/webpack/bundle5.js:138243:13)
at <unknown> (file:///~/next.js/examples/with-babel-macros/node_modules/.pnpm/next@12.0.0_react-dom@17.0.2+react@17.0.2/node_modules/next/dist/build/babel/loader/index.js:33:61)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 23 (12 by maintainers)
Commits related to this issue
- Bump `@vercel/nft` to 0.17.2 (#33048) This bumps `@vercel/nft` to the latest version and consequently bumps `graceful-fs` to the latest version. - Fixes #33003 - Related to https://github.com/vercel... — committed to vercel/next.js by styfle 2 years ago
- Bump `@vercel/nft` to 0.17.2 (#33048) This bumps `@vercel/nft` to the latest version and consequently bumps `graceful-fs` to the latest version. - Fixes #33003 - Related to https://github.com/vercel... — committed to natew/next.js by styfle 2 years ago
@ljharb upgrading to
next@12.0.8-canary.19did indeed fix this issue for me.I came across the error by using babel-plugin-inline-react-svg for reference.
Great to hear. I’ll close this once v12.0.8 of next is published.
In summary:
resolvestarted usingthrowIfNoEntrywithfs.statSyncgraceful-fshad a bug withthrowIfNoEntry, which was fixed in v4.2.9. (Usingresolvev1.2andgraceful-fs` < 4.2.9 in combination is one way to trigger the bug)nextprior to v12.0.8 sadly bundles, transitively, a version ofgraceful-fsearlier than v4.2.9 (if they hadn’t bundled this, then users would have been able to fix it themselves. since@vercel/nftswitched to not using graceful-fs to monkeypatch the environment, this won’t likely be a problem in the future)Done in https://github.com/vercel/nft/issues/257
@ljharb it’s not depending on the package manager - npm, yarn, pnpm have the same issue (confirmed this morning). You could use https://github.com/vercel/next.js/tree/canary/examples/with-babel-macros as a quite simple reproduction for testing. Simply clone it and run “npm install && npm dev” to see the error in the browser.
About v2 working: I’ve pinned both version (v1.20 and v2) and both were working for me.
I think it may be the case that the changes in v1.21 are triggering bugs in multiple packages (
graceful-fsand@babel/coreat least) as I don’t think my babel-macro-setup is dependent on graceful-fs afaik.@ljharb Yep, it does appear that using 4.29 of
graceful-fsaddresses the issue we were seeing.Can confirm, we ran into the same issue with version 1.21.0 with a dependency that referenced
@babel/core. We had to pinresolveto version 1.20.0 to correct the issue. We think this change in version 1.21.0 is what’s causing it:My guess is that libraries were depending on the error being thrown to determine that the file / directory wasn’t present.
next@12.0.8 is released, so I’m going to close this.
Cypress still needs to do a fix (https://github.com/cypress-io/cypress/issues/19610), and meteor-tool (#271), but everything else seems to be fine, and none of this has been an actual problem with
resolve.Thanks for reporting!
Looks like
next@12.0.8-canary.19may solve this - if someone could try it out and confirm, that’d be great.@benbender looks like the issue needs to be filed on
nextitself, since that’s the package doing the problematic bundling.@benbender right, that’s what i’m saying. next doesn’t require graceful-fs, it bundles it - so you have no ability to alter which version of graceful-fs it’s using.
Which means that v1.21.0 of resolve’s new usage of
throwIfNoEntryis what’s triggering the bug in an unfixed graceful-fs that’s bundled inside of next itself.