opennextjs-netlify: [Bug]: ESM not supported with Netlify functions? (part 2)
https://github.com/netlify/next-runtime/issues/1456#issuecomment-1997058498
But just to be absolutely clear, Deploy Previews are currently using
[@5](https://github.com/netlify/next-runtime/issues/1456#issuecomment-1994377971)which causes all deploys to fail for users who have opted in to the Next.js v5 Runtime. (both Deploy Previews on new pushes to branches and also regular deploys from new pushes to the main branch)So without my workaround, the opted-in Next.js v5 Runtime is unusable.
Looks like there are potential issues with deploy previews.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 6
- Comments: 30 (3 by maintainers)
same issue here with next.js š¦
I have also got this issue with my Next.js project. The issue affects both the Netlify functions (
/netlify/functions/) and Next.js APIs (/src/pages/api/).Using
netlify devwill run the project correctly on local, but not when deployed to Netlify itself.I started up my project using the T3 App tool and changed none of the configuration settings out of the box, and ran directly into this problem when adding an API.
This is a major failing of the Netlify Next.js environment and a complete blocker to my project. I didnāt want to but Iāll have to switch to Vercel to meet my deployment deadline at this point. I was only linked to this bug report after a couples weeks of posting on your forum and raising a support ticket.
I did discover that if you remove any
pathconfig from the Netlify functions it seemingly will work, at least in my reduced test case, but my APIs were all written with path parameters, so this wasnāt a viable workaround for me.Minimum replication repo: https://github.com/timothy-bailey-redbox/t3-dash-test Forum conversion: https://answers.netlify.com/t/netlify-functions-es-module-error-when-using-paths-config/111942
Running on Node v20, with Next.js 14.
Checking dependencies
@netlify/plugin-nextjs@4.41.3uses@netlify/ipx@1.4.6which usesipx@1.3.1which is quite old. Latest is v3 but Iām afraid there is much interest as i guess Netlify is planning to advocate new Native optimizerā¦BTW almost all 3 major versions of IPX use dual ESM/CJS exports with explicit import extensions (unpkg v3 - unpkg v1.3.1).
Please let me know if I can do to help for this or if you spot any bundling issues, i can trigger a hotfix also for 1.x however Iām note sure issue is originating from ipx.
This is a hard blocker for a project I am on, unfortunately. We have an existing Next.js v13 app deployed to Vercel that is authored in ESM using
type: "module"inpackage.jsonto allow for top-levelawait(which we depend on for reasonable ergonomics when working with slonik). We were looking to migrate to Next.js to get around some issues weāve had with Vercel. On Netlify the build process runs flawlessly, but the serverless functions (e.g.,___netlify-handler) just fail due to their produced code usingmodule.exports = require("...").Hereās a minimal reproduction of the issue: esm.zip
@karlhorky - Thanks for the extra info. Weāll take a look at that now.
Potential Workaround
@MarcL @orinokai is this fix contained in the āNext.js Runtime v5ā feature (currently
@netlify/plugin-nextjs@5.0.0-rc.4) that was just offered to me in early access?I just saw this in my Netlify dashboard under the Deploys page
Maybe people in this thread can try this out and we can see whether this helps⦠(it was offered to me on the Deploys page of the site)
Yeah, the issue is still open. If you have something to add feel free, but please stop with +1 posts with no additional contextāthey notify all participants and anybody else that has subscribed to the issue looking for a solution. There are already 20+ people on the thread, and likely many more following. If you want to just support add a š to the first post and move on.
+1 on this. Still an issue
As a paying Netlify customer, I find this super annoying. Especially given how long this issue has been open. Itās 2024, and being unable to set
"type": "module"because the run time canāt be bothered to support modern standards feels very archaic.@pieh @ascorbic @orinokai @danez @sarahetter any chance of getting the fix mentioned in the PR published soon?
Or at least an officially-blessed workaround?
cc IPX maintainer @pi0 (
_ipx.jsis the failing file in the error messages above)Iāve had the same issue. Turns out that my package.json had
"type": "module",in it, which wasnāt needed. Removing this has fixed the issue. I think the built netlify functions look for the nearest package.json. Because it was amodulethen thatās what caused the issue.What is strange is that mine worked with module for a good week or 2, so something that has been added has triggered this. At the moment I donāt have time to debug what that package is š¤·
I am having the same error. I have a next.js project with
"type": "module"in the package.json.Any update on this?
Hi, Iām having a similar issue.
To see the error message, try to load this image: https://gamliela.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fproject-setup-ready.e736f9d0.png&w=1200&q=75
netlify.toml(sitegamliela-website):Source code: https://github.com/gamliela/website/tree/master
I also added NODE_VERSION and AWS_LAMBDA_JS_RUNTIME in the UI, as advised in this thread, but it didnāt help.