next.js: The development mode no longer works with a library imported via Yalc
Verify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 16.13.1
npm: 8.5.3
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.1.0
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
Since I use version NextJS “12.1.0”, when I launch my application in development mode, I have an error in the server console:
$ next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Loaded env from C:\dev\dev\XXX\XXX-core\.env.local
info - Loaded env from C:\dev\dev\XXX\XXX-core\.env
warn - SWC minify release candidate enabled. https://nextjs.org/docs/messages/swc-minify-enabled
Prepare XXX build client side
Prepare XXX build server side
error - ./.yalc/@XXX/XXX-customers/dist/customers/XXX/index.js
Module parse failed: Cannot use 'import.meta' outside a module (219:16)
File was processed with these loaders:
* ./node_modules/next/dist/compiled/@next/react-refresh-utils/loader.js
* ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js
You may need an additional loader to handle the result of these loaders.
| // still a Refresh Boundary later.
| // @ts-ignore importMeta is replaced in the loader
> import.meta.webpackHot.accept();
| // This field is set when the previous version of this module was a
| // Refresh Boundary, letting us know we need to check for invalidation or
Note that before I was using version 12.0.4 and that I use yalc link to reference my custom library locally
Expected Behavior
my application launches correctly in development mode (without error) and manages to use my custom library imported with “yalc link”
To Reproduce
Use a next application in version 12.1.0, reference an external NPM library with “yalc link”
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 6
- Comments: 17 (5 by maintainers)
I narrowed the problem down to version >14.1.4 in our application. Every Next version higher than that would block the dev mode.
For me adding
"@babel/runtime": "^7.24.6"to the resolutions inpackage.jsonhelped fix it. When runningyarn install, it removed duplicate/stale/old versions. After that I removed the “resolution” and everything still works fine.Here is a minimal reproduction: https://github.com/VulcanJS/repro-bug-yalc-next-12-1
A package that uses ES modules and depends on another package that also uses ES modules (say react-konva) cannot be linked via Yalc (and maybe with yarn link as well though I have only tested Yalc), as it will be treated as a local package by Next instead of an external. Next is probably tricked by the symlink to a local package, and thinks it should build that package.
i have also faced same issue and just updated nextjs app
Seems that fix for that issue in that commit #60563
I’ve fixed that for my next.js version (13.5) with a webpack hack
So that monkey patching fixed all errors… This isn’t the best solution, and it’s similar to how I used to manage the configuration for CRA. But we have to go with what we have…
I occur the same error message when I upgrade nextjs 13 to 14, but the error related to package:
@mui/icons-material.my solution is:
I’m currently facing this issue as well. I’m developing a UI component library and I’m using
yalcto publish it locally. And when I doyalc add my-libraryinside a freshly created next.js app I get an error that the module was not found