Closed remy closed 6 years ago
I think this is due to this.
(You probably need the experimentalDynamicImport
flag).
@surma I'm using that in the rollup config. When I remove the commonjs plugin, the dynamic import works, but when it's included (so I can import cjs packages) the rollup errors.
Weighed in on Twitter already, but I cloned the repo and ran into a Babel issue (Unknown plugin "transform-runtime"). When I commented out the Babel plugin, it built successfully. Could any of your dependencies be out of date? (It doesn't look like they are, and there's even a lockfile in the repro, but I can't think what else could cause that...)
Also worth noting that dynamic imports is still not an official JS feature. Maybe you need to tweak your babel config to make babel understand them.
I've just updated the test repo to remove the transform-runtime thing. Not sure why or how that was in there (or how it was running locally for me), but without it, I get the same error:
[!] (babel plugin) SyntaxError: /Users/remy/Sites/clones/rollup-plugin-commonjs-issue/a.js: Unexpected token (1:10)
…though, now it's complaining from inside the babel plugin - but with the same error that came from the commonjs plugin.
I just tried removing the babel plugin from my real project, but then it's complaining about the JSX in the project… again, I'm new to rollup, if there's a template for doing react with code splitting then that's all I'm really trying to achieve.
I think it's this: https://github.com/rollup/rollup-starter-code-splitting + react/jsx syntax.
@remy Which plugin did you removed?
@montogeek "transform-runtime" - but in fact I need this in the real project because it's transforming react and things like object spread etc. I just removed it from the test repo because it was failing to install and run.
As I stated before, it is quite possible you need to teach babel to understand dynamic imports first before you can use them. This may be the plugin you need in your .babelrc
: https://babeljs.io/docs/plugins/syntax-dynamic-import/
Going to close. I suspect the problem isn't so much the commonjs plugin, but my pitiful attempt to get everything working using the exact right set of combinations and raindances!
Thanks all - @montogeek you're helping a tonne - thank you!
I'm new to rollup, but am trying to use dynamic imports and it seems the rollup compile process works up until I include the commonjs plugin.
I've made a repo here: https://github.com/remy/rollup-plugin-commonjs-issue - directions: npm i; npm start; - should throw the following error upon trying to parse the dynamic import:
The contents of a is simply: