Theme is not exported by rxjs to rollup.js

I am trying to configure my project to use rollup as part of the transition from angular2 to AOT compilation, however I am getting the following problem.

Error: Theme is not exported node_modules \ rxjs \ Subject.js

This is my rollup.js file:

import rollup from 'rollup'; import nodeResolve from 'rollup-plugin-node-resolve' import commonjs from 'rollup-plugin-commonjs'; import uglify from 'rollup-plugin-uglify' export default { entry: 'client/main.js', dest: 'public/assets/js/build.js', sourceMap: false, format: 'iife', plugins: [ nodeResolve({jsnext: true, module: true}), commonjs({ include: 'node_modules/rxjs/**', include: 'node_modules/angular2-jwt/**', }), uglify() ] } 

Why is this happening, I followed the angular2 cookbook guide?

+5
source share
3 answers

You will need the namedExports option with rollup-plugin-commonjs: https://github.com/rollup/rollup-plugin-commonjs#custom-named-exports .

In addition, you may find it helpful to include: 'node_modules/**' instead of individual packages, since otherwise any dependencies of your dependencies bypass the plugin (in the above config, you have duplicates of include ) - maybe this is just a typo? If you need to pass multiple values, use an array).

 commonjs({ include: 'node_modules/**', namedExports: { 'node_modules/rxjs/Subject.js': [ 'Subject' ] } }) 
+9
source

I finally figured it out in my system.

The named export solution is wrong, since rollup-plugin-commonjs will handle the export to Subject.js just fine.

The problem for me was the β€œinclude” option in rollup-plugin-commonjs.

There are two problems.

Number one: when specifying inclusions in the parameters as "node_modules / rxjs / **" you must be sure that the full path is resolved where you expect it to.

Example:

I run my build command from "c: / foo / build", but my files are in "c: / my-source", then the included templates can enable "c: / build / node_modules", which means that the commonjs plugin checks whether he should handle "node_modules / rxjs / ", he will see that "c: / my-source / node_modules / rxjs / " does not match "c: / build / node_modules / rxjs / **", so he will not convert export to ES6.

The second problem is case sensitivity. Incoming templates are case sensitive. It also helped me.

Both of these problems can be confirmed by opening the file node_modules \ rollup-plugin-commonjs \ dist \ rollup-plugin-commonjs.cjs.js and debugging the transform function.

If you change the code (at the very beginning of the conversion function) to be something like this

 if (id.includes('rxjs\\Subject.js')) { debugger; } 

and then run the code in the debugger, you can go through the code until it gets into the filter function. There you will see that the filter function skips the "rxjs / Subject.js" file.

I almost guarantee that this is a problem when an error occurs.

0
source

I have discovered that this can happen in conjunction with symbolic links.

0
source

Source: https://habr.com/ru/post/1257958/


All Articles