Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Unexpected token 'export' when using in node #332

Open
tomwayson opened this issue Feb 22, 2024 · 0 comments
Open

SyntaxError: Unexpected token 'export' when using in node #332

tomwayson opened this issue Feb 22, 2024 · 0 comments

Comments

@tomwayson
Copy link
Member

I have an .mjs file that does import * as icons from "@esri/calcite-ui-icons";

when I run that script I get:

(node:92958) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/tom/code/opendata-ui/node_modules/@esri/calcite-ui-icons/index.js:2
export {i12X16} from "./js/i12X16.js";
^^^^^^

SyntaxError: Unexpected token 'export'

Note that I also tried running a .js script using const icons = require("@esri/calcite-ui-icons"); but that failed w/ the same syntax error b/c main points to the same ESM file (index.js).

Adding type: "module" to the copy of this library's package.json in my node_modules folder fixes the above error and my script runs fine. However, that will force node consumers to import this module, which may be fine, and in any case is better than the current situation which is that the module cannot be imported nor required. I'm not sure if you're supposed to drop the main entry in that case?

If you have to support both I guess you would need to transpile to CJS and point main to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant