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
I am using a package that exports es modules, these are correctly imported in the browser bundle thanks to the module field in the package.json of the dependency
The problem is that if i want to import es modules from a folder like package/esm/folder I get an error because of the exportimport syntax not supported in node, the error will be something like SyntaxError: Unexpected token import
I think this is because nodejs cannot use es modules and the package is not transpiled by webpack in the nodejs process, is this correct?
One solution would be to not use es modules and instead use only commonjs for subfolders imports (but then i cannot tree shake), or create a separate package and take advantage of the package.jsonmodule field
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using a package that exports es modules, these are correctly imported in the browser bundle thanks to the
module
field in thepackage.json
of the dependencyThe problem is that if i want to import es modules from a folder like
package/esm/folder
I get an error because of theexport
import
syntax not supported in node, the error will be something likeSyntaxError: Unexpected token import
I think this is because nodejs cannot use es modules and the package is not transpiled by webpack in the nodejs process, is this correct?
One solution would be to not use es modules and instead use only commonjs for subfolders imports (but then i cannot tree shake), or create a separate package and take advantage of the
package.json
module
fieldIs there a better solution?
Beta Was this translation helpful? Give feedback.
All reactions