You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Where my-esm-plugin is a dependency (in node_modules) that uses ESM ("type": "module" in package.json).
During config resolution, Rollup keeps node_modules as external dependencies due to this line ((id[0] !== '.' && !path.isAbsolute(id))). In this case, the file will be transpiled to something like:
constplugin=require('my-esm-plugin');
...
This is because it's treated as an external dependency (it would be bundled otherwise).
Then, since it's an ESM dependency but it uses require to import it, it will fail with [ERR_REQUIRE_ESM]: Must use import to load ES Module.
In order for this to work, node_modules should not be treated as external dependencies (by removing the mentioned line) and Rollup should use rollup-plugin-commonjs. However, I do not know if there is a drawback to this. Perhaps just performance?
I can make a PR if you are OK with these changes, or if you can propose something else.
System Info
requiredvite version: rc.13
required Operating System: macOS Catalina
required Node version: 14.15.1
The text was updated successfully, but these errors were encountered:
@aleclarson I tried for a while but couldn't make it work. Since it's treated as an external dependency, I think Rollup is not even using the interop option. Not sure about this though.
My current workaround is providing the plugin in commonJS with .cjs extension.
Describe the bug
Given the following config file:
Where
my-esm-plugin
is a dependency (innode_modules
) that uses ESM ("type": "module"
inpackage.json
).During config resolution, Rollup keeps
node_modules
as external dependencies due to this line ((id[0] !== '.' && !path.isAbsolute(id))
). In this case, the file will be transpiled to something like:This is because it's treated as an external dependency (it would be bundled otherwise).
Then, since it's an ESM dependency but it uses
require
to import it, it will fail with[ERR_REQUIRE_ESM]: Must use import to load ES Module
.In order for this to work,
node_modules
should not be treated as external dependencies (by removing the mentioned line) and Rollup should userollup-plugin-commonjs
. However, I do not know if there is a drawback to this. Perhaps just performance?I can make a PR if you are OK with these changes, or if you can propose something else.
System Info
vite
version: rc.13The text was updated successfully, but these errors were encountered: