-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Next 12 Error ESM in production, works locally #30347
Comments
Help Me |
Hi, please provide a repo with a minimal reproduction to allow further investigation. |
@ijjk I made small reproduction here Next 11 Next 12 |
I wasn't able to make a repo, but the error I'm seeing in prod that isn't there in dev reads like this:
React, ReactDOM, next and swiper are all at the latest version |
I have this error |
You should be able to fix that error by upgrading node.js from 12 to at least 14.13.0. |
Ok seems like that is related to react being replaced with preact/compat, and that doesn't export e. g. With
|
@developit could we make sure that Repo:
It need to has these named exports otherwise Note I'm talking about |
As workaround you can opt-out of preferring ESM for node_modules via:
|
I have this same issue, and setting |
node is set to 14 on vercel. locally I'm using v14.18.0, but this only happens on vercel. So sadly this didn't help. Also setting the esmExternals to false did not help either |
If it only happens on vercel, but works with local // next.config.js
module.exports = {
outputFileTracing: false,
} but just guessing. I also seems like you all might have different problems... |
Good catch @sokra - that module was authored before Node had named export inference, will update it. |
Alright, it looks like this might be related to the difference in how // @preact/compat
module.exports = require('preact/compat');
// react
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react.production.min.js');
} I believe the conditional in React's case causes Node's named (re-)export inference to fail, resulting in flat exports from CJS that are taken as named exports. Since there is no conditional in |
It's not about the conditional. Node.js actually understands that. In the
So the analyse-able exports in e. g. there is What you probably want to do is to add a |
I replaced the swiper with react-slick. |
This seems to have done the trick for my problem, thank you very much! |
@johnrackles did you need to add |
@ijjk In our case, we need I'm using Next 12.0.2 |
@revskill10 that sounds related to #30750 which is fixed in v12.0.3-canary.2 of Next.js |
yes, I just tried again and it still happenes. I'll try with v12.0.3-canary.2 and report back edit: yes, v12.0.3-canary.2 seems to fix the problem! |
12.0.3 is out now 👍 |
Hey y'all, I quickly dove into this and used the reproduction so kindly provided by @rayriffy (thank you 🙌 )! So upgrading This is mainly an assumption because I've seen it before when porting The new issue we run into then requires us to comment out the EDIT: I've tried adding EDIT 2: oh it doesn't happen when we use non-static-generation export async function getServerSideProps() {
return {
props: { hello: 'world' }
}
} it works correctly, if I remove that and it moves to The error
|
Going to close this as the initial issue has been solved. @JoviDeCroock could you post that comment in a new issue so that we can triage it? Update: I've moved that issue to #31538 |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
12.0.0
What version of Node.js are you using?
v14.17.5
What browser are you using?
Chrome
What operating system are you using?
Linux PopOS
How are you deploying your application?
Vercel
Describe the Bug
Apparently a conflict with Swiper ESM package.
In version 11 of next.js it worked.
we import normal:
import {Swiper, SwiperSlide} from 'swiper/react';
after upgrading to version 12 of the next, in development it works, but in vercel it doesn't
Expected Behavior
info - Loaded env from /var/task/.env.local
2021-10-26T18:13:28.652Z 673e2ff4-a116-4da1-87f0-59e86b91fbf5 ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"SyntaxError: Named export 'useEffect' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from 'react';\nconst { useEffect, useLayoutEffect } = pkg;\n","reason":{"errorType":"SyntaxError","errorMessage":"Named export 'useEffect' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.\nCommonJS modules can always be imported via the default export, for example using:\n\nimport pkg from 'react';\nconst { useEffect, useLayoutEffect } = pkg;\n","stack":["file:///var/task/node_modules/swiper/react/use-isomorphic-layout-effect.js:1","import { useEffect, useLayoutEffect } from 'react';"," ^^^^^^^^^","SyntaxError: Named export 'useEffect' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.","CommonJS modules can always be imported via the default export, for example using:","","import pkg from 'react';","const { useEffect, useLayoutEffect } = pkg;",""," at ModuleJob._instantiate (internal/modules/esm/module_job.js:121:21)"," at async ModuleJob.run (internal/modules/esm/module_job.js:166:5)"," at async Loader.import (internal/modules/esm/loader.js:178:24)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: SyntaxError: Named export 'useEffect' not found. The requested module 'react' is a CommonJS module, which may not support all module.exports as named exports.","CommonJS modules can always be imported via the default export, for example using:","","import pkg from 'react';","const { useEffect, useLayoutEffect } = pkg;",""," at process. (/var/runtime/index.js:35:15)"," at process.emit (events.js:412:35)"," at processPromiseRejections (internal/process/promises.js:245:33)"," at processTicksAndRejections (internal/process/task_queues.js:96:32)"]}
Unknown application error occurred
To Reproduce
1 - Install swiper@7
2 - Upgrade Next.js to version 12
3 - Publish in Vercel
The text was updated successfully, but these errors were encountered: