Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant