rollup / rollup

Next-generation ES module bundler
https://rollupjs.org
Other
25.32k stars 1.51k forks source link

Wrong error: Cannot use import statement outside a module #5236

Open lborgman opened 11 months ago

lborgman commented 11 months ago

Rollup Version

v4.1.5

Operating System (or Browser)

Windows 10

Node Version (if applicable)

v18.18.2

Link To Reproduction

https://github.com/hizzgdev/jsmind

Expected Behaviour

I forked the jsmind repository and run npm run build and got the error above.

This will run rollup -c .config/rollup.config.js.

It should build the output into the "es6" subdirectory.

Actual Behaviour

I got the error in the title.

I normally do not use rollup so I had no idea what was wrong. However I tried installing the plugins mentioned in "rollup.config.js" above.

npm install --save-dev @rollup/plugin-cleanup

This gives an error message that the plugin was not found. I was nearly giving up there, but just in case I tried the other plugin:

npm install --save-dev @rollup/plugin-terser

This fixed the problem.

vishal-1230 commented 11 months ago

temporary solution that worked for me was to put "type": "module" in package.json