Rollup config error on dynamic import during library build
See original GitHub issueType of Issue
[x ] Bug Report
[ ] Feature Request
Description
This bug relates to building angular library which uses dynamic imports.
Consider building foo
library with the command ng build foo
.
When the library contains a file (service in my case), which uses dynamic import, the build will fail throwing error below.
Error: You must set "output.dir" instead of "output.file" when generating multiple chunks.
at error (c:\Development\rollup-test\node_modules\rollup\dist\rollup.js:3410:30)
at normalizeOutputOptions (c:\Development\rollup-test\node_modules\rollup\dist\rollup.js:17107:13)
at getOutputOptions (c:\Development\rollup-test\node_modules\rollup\dist\rollup.js:16865:24)
at Object.write (c:\Development\rollup-test\node_modules\rollup\dist\rollup.js:16957:43)
at Object. (c:\Development\rollup-test\node_modules\ng-packagr\lib\flatten\rollup.js:46:22)
at Generator.next ()
at fulfilled (c:\Development\rollup-test\node_modules\ng-packagr\lib\flatten\rollup.js:4:58)
How To Reproduce
See details about how to reproduce at this post: https://github.com/angular/angular-cli/issues/14444#issue-444906345
Issue Analytics
- State:
- Created 4 years ago
- Reactions:38
- Comments:51 (3 by maintainers)
Top Results From Across the Web
rollup.js
Import modules using the dynamic import API. import('./modules.js').then(({ default: DefaultExport, NamedExport }) => { // do something with modules. });.
Read more >@rollup/plugin-dynamic-import-vars - npm
A rollup plugin to support variables in dynamic imports in Rollup. ... Create a rollup.config.js configuration file and import the plugin:.
Read more >How to dynamically import a module which name is defined by ...
Unfortunetely i found that rollup doesn't support variables in dynamic imports for now. Please see these issues:
Read more >Features | Vite
Vite will detect such bare module imports in all served source files and perform ... via dynamic import and will be split into...
Read more >Code Splitting - webpack
Dynamic Imports : Split code via inline function calls within modules. ... webpack-demo |- package.json |- package-lock.json |- webpack.config.js |- /dist ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree with @blemaire. In a plugin context you want the library to be autonomous. Even more when you deal with non routed lazy-loaded component.
If you take my exemple in earlier post, why a plugin button which call a modal could not take the responsability of it ? THIS look like a bad pattern to me.
The issue may come from https://github.com/ng-packagr/ng-packagr/blob/master/src/lib/flatten/rollup.ts#L69 when there is dynamic import, rollup will try to use
output.dir
instead ofoutput.file
to build multiple bundles.For me, the library I am trying to build is not entirely depends on Angular. So I just use typescript-library-starte and override the https://github.com/alexjoverm/typescript-library-starter/blob/master/rollup.config.ts#L15 to
output.dir
then will have the following issue https://github.com/rollup/rollup/issues/2072 which just says umd bundle format is not compatible for dynamic import. As I googled what that means, one of github issue saysIIFE and UMD formats are (purposefully) self-contained
https://github.com/lukeed/navaid/issues/5#issuecomment-488540276It seems a lot of effort to make umd support dynamic import. For now I guess the best way right now is to support rollup build multiple bundles and add a ng-packagr option to disable umd build.