-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Invalid "Native Node.js APIs are not supported in the Edge Runtime" error message #36237
Comments
I'm experiencing a similar issue after updating my NextJS app to React v18. I have some packages installed that under the hood make use of native Node APIs such as
Downgrading to react v17 solves the problem |
@riboher I have just had the same problem and found this issue. When I I can remember have had similar problems with this in the past |
Is there any workaround other than downgrading React to v17? |
I also get this error message due to importing 'fs' (i.e., |
I get this error too while trying to use twilio video, and downgrading React to v17 didn't help. Any ideas? |
To clarify, basically you cannot use Node.js modules on middleware (edge functions), so it's expected that This issue is about displaying the error message on wrong conditions. |
I've the same problem when switched to React 18. I'm using custom entry points for workers which worked fine before switching to R18. Now, the build is failing on node.js native stuff too (like the others here), for example because of Prisma Client. In general, I don't care about some "Edge Runtime" in which case I even don't know what it is or why it even exists or why it's so aggresively pushed inside the build (for Vercel or some serverless stuff, I'm ok), but I'm doing standard build for standard node.js env. so I expect the build to work as standard too, not like this: |
- improve the message for importing node builtin module on edge runtime - fix to show the message on overlay of error browser with `next dev` - fix #36237 The message is NOT shown when using edge runtime (not middleware) since I cannot find a way to detect a webpack compilation is for edge runtime. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
Apologies for commenting here, but @marek-hanzal's issue is also my issue and I was able to solve it. The "edge runtime" is a third webpack config that Next is using. This means that to add an extra entry to your webpack config, you need to use the webpack: (config, { nextRuntime }) => {
// Undocumented property of next 12.
if (nextRuntime !== "nodejs") return config;
return {
...config,
entry() {
return config.entry().then((entry) => ({
...entry,
cli: path.resolve(process.cwd(), "lib/cli.ts"),
}));
},
};
}, To explain, this function gets called with |
This variable is exported by next but undocumented, and its usage is necessary to build auxiliary scripts for your server-side applications. See vercel#36237 (comment) for an example.
This variable is exported by next but undocumented, and its usage is necessary to build auxiliary scripts for your server-side applications. See #36237 (comment) for an example. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint`
Hey @CGamesPlay, thank you for this! It fixed my issue as well! In my case, I had to actually check that the runtime was |
Yep, I can confirm I've solved that issue same way. It was quite hidden there. But now it works. |
Docs should be updated #36685, thanks to @CGamesPlay! |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When there is a page like the following,
next build
shows the error message> Native Node.js APIs are not supported in the Edge Runtime. Found "child_process" imported, on index.
, even when there is no middleware used.This is the same for the compilation error using
next dev
.Also, a related problem, but when you use react version 17, this message is NOT shown for middleware importing
child_process
.Expected Behavior
The error message is shown only for edge functions certainly, even with older react version.
To Reproduce
Import the
child_process
module on a page, without middleware, with react@18.The text was updated successfully, but these errors were encountered: