Cannot use dynamic imports for ESM packages
See original GitHub issue- Do you want to request a feature or report a bug? Bug
- What is the current behavior? When deploying to Netlify, the deploy itself succeeds, but the deployed site throws errors whenever a dynamic import is encountered.
- unspecified
node_bundler: Error: Cannot find package ‘unified’ imported from/var/task/netlify/functions/server/build/index.js node_bundler = "esbuild": Error: ENOENT: no such file or directory, open<path to my project>/.netlify/functions-serve/server/src/netlify/functions/languages/abap.tmLanguage.jsonnode_bundler = "esbuild"&external_node_modules = ["unified"]: Error: Must use import to load ES Module:<path to my project>/.netlify/functions-serve/server/src/node_modules/unified/index.js
Locally via netlify dev, things do work when neither node_bundler nor external_node_modules is specified, but does not work on Netlify remotely.
If node_bundler = "esbuild", then I get the ^above errors on routes relying on unified.
- If the current behavior is a bug, please provide the steps to reproduce.
- Create a new Remix app
npx create-remix@latest - Select “Netlify” as the deployment option
- Create a route that imports
unified(or any other ESM-only package) dynamically - Deploy to Netlify
I’ve noticed that locally, when esbuild is used, a .netlify directory is created and the transpiled code has replaced dynamic imports with require calls, causing Error: Must use import to load ES Module.
- What is the expected behavior?
esbuild keeps dynamic imports and does not replace them with require calls.
- Please mention your node.js, and operating system version.
MacOS 11.6.1 Node 14
I’ve tried debugging this on the Remix side of things, but right now I’m stuck trying to figure out how netlify dev’s usage of esbuild is transpiling things such that dynamic imports are replaced by require calls.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)

Top Related StackOverflow Question
I was able to get things working by adding
shikitoexternal_node_modules:shikirelys on a bunch of.jsonfiles for its (programming) language support as well as for its themes.abap.tmLanguage.jsonwas one of the language files it needed.The warnings about
unifiedjust threw me off.I freaking love you guys! I did spend half a day trying to fix one of my imports… Thank you!!!