How to solve module.id there should be a string error using webpack2

So, I am using webpack2 in an Angular2 project that has several external dependencies. Some of these dependencies use commonjs and declare components, as shown below:

@Component({ moduleId: module.id, templateUrl: 'mycomponent.html' ... }) 

This results in the error below:

 Error: moduleId should be a string in "MyComponent" 

After some research, I realized that this is because Webpack expects components to have id as a number, and Angular will declare it as a string. I cannot change the dependency code. What can I do to live with such an addiction?

Thanks!

+8
source share
3 answers

So, here is what I came up with to live with this addiction now. Use the line replacement loader to remove this line for me:

 { test: /.*node_modules\/my-dependency-folder\/.*\.js/, loader: 'string-replace-loader', query: { search: 'moduleId: module.id,', replace: '' } } 

Hope this helps someone with the same issue.

+3
source

I don’t know if this will help or not, but maybe someone will need it (I did!).

Therefore, in the worst case, you can find module.id in .js files and add the .toString() method (module.id.toString() ), this will solve the problem.

+1
source

Delete line

 moduleId: module.id, 

He works.

0
source

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


All Articles