-
-
Notifications
You must be signed in to change notification settings - Fork 461
Error: Cannot find module 'next/dist/next-server/server/node-polyfill-fetch' #440
Comments
Hi could you post your |
@danielcondemarin Hello. Please see below: serverless.yml
|
This sounds like the new fetch polyfill they shipped with 9.4: https://nextjs.org/blog/next-9-4#improved-built-in-fetch-support. I am not sure why it's breaking for you now, but I imagine #431 could fix your issue. Note that it hasn't been released yet. You can test it by cloning this repo locally, building it like is described in CONTRIBUTING.md then pointing to its local path in your serverless.yml like |
@lone-cloud Am I correct in assuming that version 1.14.0-alpha.0 has the branch you mention above in it? |
Yes, I'm fairly confident (I didn't create the release) that's the case. |
@lone-cloud I'm getting the same error with the release and with the branch. |
@standingdreams Could you try using |
@danielcondemarin: please see below. next.config.js
|
@danielcondemarin When I add
When I remove that line from serverless.yml, it deploys again and I go back to having the old error. |
@danielcondemarin Yes. It's enabled. |
@standingdreams are you using yarn workspace? |
@eenagy No, just NPM. Do you think Yarn would produce different results? |
@standingdreams no, it's not related to yarn, but having using workspace on my side, I have a similar issue when node_modules is not deploying correctly. |
@danielcondemarin @lone-cloud @eenagy |
Yes, that makes sense as the polyfill in your stack trace would only be loaded on the server. If you don't define those functions, your code will not be rendered on the server. |
I'm also using yarn workspaces and was able to reproduce this error on dynamic routes. The fix was to add this to my
|
Hey, guys. I am getting the same with:
workspaces.nohoist doesn't help much. If I open the deployed Lambda function code, visually it looks the same as before. I am doing serverless.yml:
|
I confirmed this one. You can also copy the configuration files to root before running npx serverless on CI/CD. This makes nextConfigDir & userServerlessTraceTarget unusable together. Please fix! :) |
Is there a solution for this thread yet? |
@DeerajTheepshi sorry I had not looked at this issue since it was older (need to clean up more old issues some time...). It sounds like a bundling issue, is it a problem on Vercel as well? What Next.js version are you using? Is it reproducible on the latest version of Next.js? I know they changed how they bundle things somewhere around 10.2, so it might have been fixed in later versions? If you could provide a repro I can take a look, maybe we can just try to include the |
We are using Next version : 10.2, and I'm not able to share the repo as it's private and belongs to a work organisation. I will try to make a minimal version of it. As mentioned above the issue happens whenever we try to run any kind of server code. Will try upgrading next to a higher version. |
After going through cloudwatch logs, I tried removing the dependency line from the file where the error was thrown. The dependency was unused, so I tried it. But after that it threw "Module Not Found" error on a different package, namely : On upgrading next to 11.0.1, I got the following error: I also forgot to add one important note, that this happens for an ISR page. The error logs are from the SQS triggered lambda. Any idea on what may be happening? |
@DeerajTheepshi please confirm you are using the latest component version? The missing chunks issue should have been solved as in some versions they were not included incorrectly, I think some patch version of 10.2 started splitting chunks differently. So we had to start including those chunks as well. I am not sure why there are One possible workaround is you can try to manually copy the |
I can confirm from Template.json file that the version we are using is 3.1.0. The development build and behavior of ISR pages are as expected in the local deployment. That's why I believe that the error may be from the component. Here's what I observed, the SQS triggered lambda doesn't contain a node_modules/chunks folder at all, whereas the default_lambda has all the files as expected and that's probably why SSR works and only ISR fails. Should I move this to #1098 |
So things worked from me when I added postBuildCommands to move ISR is working fine as expected. My only doubt is, is this the expected setup ? Shouldn't the component do this ? |
@DeerajTheepshi yep, it is a bug you found in ISR, the component should handle if it's part of standard Next.js build. I will try to reproduce it but from seeing the code here (
|
@DeerajTheepshi from linked issue #1317 looks like there could be a similar root cause. I guess we need to check if there are some files not copied from |
@DeerajTheepshi actually after doing some more testing on 10.2.0 I did notice regeneration lambda does not seem to copy the traced node modules correctly (although there is a call here
If you are using 10.2.0 Next.js hadn't changed the chunking yet, so serverless-trace is still supposed to use I think if you can upgrade to 10.2.3 at least, its new chunking should solve these problems as well, although I am fine fixing here as well, since it should be a small fix and wasn't working correctly in the first place. Have fixed copying node_modules for earlier versions of Next.js where serverless trace is possible: https://github.com/serverless-nextjs/serverless-next.js/pull/1319/checks?check_run_id=2936339320 If there is still an issue after this is published, let me know. |
@dphang , thanks for the quick fixes. Sorry I couldn’t reply earlier. Yes we were using Serverless trace target. One thing to note is the missing chunks error happened when we upgraded to 11. Will update once I test out the next release. Thanks |
I came across this issue. However, after upgrading to the following this bug has gone and Incremental Static Regeneration (ISR) is working:
|
Thanks for confirming, I think these sorts of issues should now be fixed (especially in latest versions where bundling from Next.js itself was improved, and also we should be including the node_modules correctly in the serverless trace mode). So I'll resolve this. If it resurfaces, please open a new issue. |
While deploying a Next.js app to AWS using Serverless, I get a 503 error. When I drill down into the logs, I find the error I'm recieving is
Error: Cannot find module 'next/dist/next-server/server/node-polyfill-fetch'
.I've tried uninstalling and reinstalling. I was using the latest version of Next. I tried to downgrade to 9.3.4. I've tried to downgrade Serverless Next.js. I've tried downgrading Node from 12 to 10 in Cloudfront. Any help would be greatly appreciated.
Please let me know if there is any other information needed to help with this issue.
"serverless-next.js": "^1.13.0"
"next": "^9.3.4"
Full error message
The text was updated successfully, but these errors were encountered: