-
Notifications
You must be signed in to change notification settings - Fork 35
Cannot use dynamic imports for ESM packages #869
Comments
Hey @pcattori, thanks for letting us know of this issue! Looking into it :) |
I followed the steps you gave, but didn't set the This is the dynamic import I added to Here's my site: https://zisi-869-repor.netlify.app. I was able to verify this is working by looking at the Function's logs: You mention Having a full reproduction repository would be helpful, so I know exactly what needs to happen to reproduce the error. |
Trying to reproduce here: https://github.com/pcattori/remix-netlify-dynamic-imports . So far I've just included a dead-simple export const loader = async (): Promise<LoaderData> => {
const { unified} = await import('unified')
const { default: remarkParse } = await import('remark-parse')
const { default: remarkRehype } = await import('remark-rehype')
const { default: rehypeStringify } = await import('rehype-stringify')
const transpiler = await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeStringify)
const html = await transpiler.process('# Hello, Neptune!')
return { html: String(html) }
} That is working perfectly fine! I also tried adding some 1st-party I'm going to try to replicate my actual |
I was able to get things working by adding [functions]
node_bundler = "esbuild"
external_node_modules = ["shiki"]
The warnings about |
I freaking love you guys! I did spend half a day trying to fix one of my imports.... Thank you!!! |
Thank you SO much @pcattori. Exact same issue with |
- 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.
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.json
node_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 neithernode_bundler
norexternal_node_modules
is specified, but does not work on Netlify remotely.If
node_bundler = "esbuild"
, then I get the ^above errors on routes relying onunified
.- If the current behavior is a bug, please provide the steps to reproduce.
npx create-remix@latest
unified
(or any other ESM-only package) dynamicallyI've noticed that locally, when
esbuild
is used, a.netlify
directory is created and the transpiled code has replaced dynamic imports withrequire
calls, causingError: Must use import to load ES Module
.- What is the expected behavior?
esbuild
keeps dynamic imports and does not replace them withrequire
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 ofesbuild
is transpiling things such that dynamic imports are replaced byrequire
calls.The text was updated successfully, but these errors were encountered: