-
Notifications
You must be signed in to change notification settings - Fork 65
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
Yarn berry PnP + Next.js 12 has import error. #163
Comments
The ESM support for PnP in yarn is still experimental. Meanwhile, you can set Sources: |
I'm not familiar with Yarn PNP. Does a library author have to config their library is a specific way to work with Yarn PnP? My assumption was that it should just work. |
On the top of the issue I sent, the user says: I often use TS to "compile down" to |
I just ran into this issue as well when enabling SWC compiler when using Yarn Berry PNP. Can't quite tell from the yarn GH issue if this is resolved or not 🤷 It looks like the release for yarn berry 3.1.0 enables some ESM support but I'm still seeing this NextJS issue on that version 🤷 I tried adding |
next-connect is provided with both ESM and commonjs version. As it appears to be due to Yarn PnP not handling ESM probably, we can try to disable ESM in Next.js. One can also try to patch next-connect package.json to remove any reference of ESM (remove the exports field, leaving only the main field) {
"name": "next-connect",
"version": "0.11.0",
"description": "The method routing and middleware layer for Next.js (and many others)",
"keywords": [
"javascript",
"nextjs",
"middleware",
"router",
"connect"
],
- "type": "module",
"main": "dist/index.cjs",
- "module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
- "exports": {
- ".": {
- "require": "./dist/index.cjs",
- "import": "./dist/index.js"
- }
- }
} |
Using
|
Sounds promising. How to test that? I've never made a own npm plugin and have no idea how to do that. |
Should have been fixed in yarnpkg/berry#3667 yarn set version canary && yarn install
@hoangvvo No, as long as you declare all the dependencies you use and use Node builtins to deal with resolving modules everything should just work on its own |
Awesome work! Thanks a lot |
I fixed this issue after changing Docker settings. My new Dockerfile
|
error - Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'next-connect' imported from /app/.next/server/pages/api/test_endpoint.js
The text was updated successfully, but these errors were encountered: