Angular No module factory available for dependency type: ContextElementDependency

后端 未结 3 1269
感动是毒
感动是毒 2020-12-07 22:41

Running ng build on my Angular 4 project give this error :

     14% building modules 40/46 modules 6 active ...es\\@angular\\http\\@angular\\htt         


        
相关标签:
3条回答
  • 2020-12-07 23:18

    So i was having this issue and it took me forever to figure out. I kept trying to delete my node_modules directory then reinstall webpack. If i installed webpack locally or globally i would get the ContextElementDependency error. If i uninstalled webpack i would get webpack not found. Long story short the problem for me was my package-lock.json file. So i ran "rm package-lock.json && rm -R node_modules" and then i could successfully run "npm install" and "npm start". Dont ask me why this works, but i hope this helps someone.

    0 讨论(0)
  • Steps I took to fix this problem in case if someone encounters it:

    1. Package.json: remove webpack from DevDependencies
    2. rm -R node_modules (remove node_modules folder)
    3. npm i -g webpack
    4. npm i -g webpack-dev-server
    5. remove package-lock.json (if it's there)
    6. npm i
    7. npm start

    I still don't completely understand the reasons why this happened.

    0 讨论(0)
  • 2020-12-07 23:35

    Do npm ls webpack

    If you see two versions of webpack (under @angular/cli and the root node_modules), Then that is the problem. Delete/Rename the webpack under @angular/cli and in the .bin folder of @angular/cli.

    Problem solved for me

    0 讨论(0)
提交回复
热议问题