-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Build fails to compile - module not found: can't resolve "child_process" 12.1.6 #36776
Comments
Note that you should not use Node-specific APIs in your Middleware as it uses the Edge Runtime. (See the docs: https://nextjs.org/docs/api-reference/edge-runtime#unsupported-apis). Sentry does not seem to be compatible at the moment. Maybe related #36237 (comment) Could you add a small reproduction to verify? |
Sentry works fine in middleware in 12.1.5 @balazsorban44 wondering what changed? |
These |
It also break experimental: {
runtime: 'nodejs'
}, Doesn't help ;\
|
Seems to be breaking Prisma, Upstash, etc within Middleware files, not sure if this is a new "stricter" middleware setup or if the version is broken. |
So up until recently, we have polyfilled a few Node.js APIs even for the Edge Runtime. This has been changed in #36190 as it was the original intention as documented: https://nextjs.org/docs/api-reference/edge-runtime#unsupported-apis Any library relying on that did so by mistake. |
@sergeyshaykhullin the switchable runtime does not concern Middleware, we added a note about this in the docs to make it more clear: #36862 Also in the Middleware docs there is this:
So this should explain your situation. I'm closing this as the result is expected. A final word on Sentry, they don't have official Middleware support yet: getsentry/sentry-javascript#4206 |
@balazsorban44 thanks! Ive stripped sentry out of the API calls we were making at the middleware level and all is working now. |
@balazsorban44 Does that mean i can't do http requests inside middleware? |
@sergeyshaykhullin You can still use Also as a side note: I think the issues I was facing may have been due to a custom webpack config within the next config file, will do more testing later |
Improved the documentation here: #36862 |
@balazsorban44 In case I fetch CMS data (we use Sanity.io) in a middleware/Edge function and their client relies on unsupported Node modules, I have only two choices:
Is that right? |
You should not be using Middleware to fetch CMS data, check out our data fetching documentation for that. |
Maybe I should've explained the use case: the redirects are managed by content editors -- for SEO, etc. -- then they're stored in the CMS. We have a site-wide middleware that looks up for redirects using the Sanity.io client. That's why we fetch CMS data in a middleware. Perhaps, we could add polyfills for the required node modules to our own codebase? |
Very curious in this use case as well, as I have wanted to do something similar in our Contentful setup to allow my team to handle setting up redirects in the CMS. Currently, it's a manual process to add them to |
@wadehammes Here is a simplified version of the middleware I mentioned, just to illustrate how it can be done:
The type of the
But I guess you get the idea. |
@straube awesome implementation, we use middleware for AB test identification and page redirects (with Launch Darkly) which works perfect (we use the fetch API to hit custom internal endpoints that handle the Launch Darkly identify and flag retrieval), wondering if you could leverage something similar (not familiar with Sanity) but the more I think about it I could probably do the same with Contentful and just hit their endpoint (and pass the pathname as a param) instead of using their SDK (which would fail due to the node module issue). |
Just answering my own question here: no. I tried that and some polyfills rely on |
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
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Wed Mar 2 00:30:59 UTC 2022
Binaries:
Node: 14.18.1
npm: 6.14.15
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 12.1.6
react: 18.1.0
react-dom: 18.1.0
What browser are you using? (if relevant)
Firefox
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
In the latest 12.1.6, I can't get my site to compile on Vercel. Everything works fine in previous release. See log below. I am not sure if this is a Sentry issue or an issue with next.
Expected Behavior
Site compiles like in 12.1.5
To Reproduce
Have a next site set up with Sentry initiated at webpack level.
The text was updated successfully, but these errors were encountered: