angular-cli: build aot: Error: No module factory available for dependency type: ContextElementDependency
OS?
angular-cli: 1.0.0-beta.26
node: 6.9.4
os: win32 x64
@angular/common: 2.4.5
@angular/compiler: 2.4.5
@angular/core: 2.4.5
@angular/forms: 2.4.5
@angular/http: 2.4.5
@angular/language-service: 2.4.5
@angular/platform-browser: 2.4.5
@angular/platform-browser-dynamic: 2.4.5
@angular/router: 3.2.1
@angular/compiler-cli: 2.4.5
Repro steps.
Repo: https://github.com/born2net/studioweb
The log given by the failure.
Trying to ng build aot
dump:
$ ng build --aot
25% building modules 128/230 modules 102 active ...modules\@angular\core\src\metadata.js
An error occured during the build:
Error: No module factory available for dependency type: ContextElementDependency
at Compilation.addModuleDependencies (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:186:21)
at Compilation.processModuleDependencies (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:175:8)
at _this.buildModule.err (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:315:13)
at building.forEach.cb (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:125:27)
at Array.forEach (native)
at callback (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:125:13)
at module.build (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:147:11)
at ContextModule.<anonymous> (C:\msweb\studioweb\node_modules\webpack\lib\ContextModule.js:118:3)
at ContextModule.result.resolveDependencies (C:\msweb\angular-cli\packages\@ngtools\webpack\src\plugin.ts:195:25)
at ContextModule.build (C:\msweb\studioweb\node_modules\webpack\lib\ContextModule.js:99:7)
at Compilation.buildModule (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:127:10)
at factoryCallback (C:\msweb\studioweb\node_modules\webpack\lib\Compilation.js:304:11)
seems the entire stack is from Webpack and no ref to any part of my code
Regards,
Sean
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 7
- Comments: 30 (4 by maintainers)
I had the issue because i manually installed webpack so i had webpack2.3.1 for a different process in the project and was able to fix it by using webpack~2.2.0. Hope that helps.
@LasTanzen Thanks for the great tip! I just removed webpack from the DevDependencies and it works
Try reinstalling webpack. It worked for me. It seems it has some issues building factories for new components sometimes and needs to be reinstalled. So I did:
Hope it helps.
Reference:http://dxtright.com/index.php/2017/12/05/angular-no-module-factory-available-dependency-type-contextelementdependency/
same issue here
npm ls -g --depth=0
package.json:
ng serve
source repository: https://github.com/rudzikdawid/material2-start
I am running into this issue when trying to upgrade my angular project to universal using Everton Roberto Auler’s angular-cli-demo.
@angular/cli: 1.1.3 node: 6.10.0 os: linux x64 @angular/animations: 4.2.4 @angular/common: 4.2.4 @angular/compiler: 4.2.4 @angular/compiler-cli: 4.2.4 @angular/core: 4.2.4 @angular/forms: 4.2.4 @angular/http: 4.2.4 @angular/platform-browser: 4.2.4 @angular/platform-browser-dynamic: 4.2.4 @angular/platform-server: 4.2.4 @angular/router: 4.2.4 @angular/cli: 1.1.3
I am using webpack ~2.2.0 as you can see here and I have read above this problem was supposed to be obsolete due to recent changes in cli. “tslint”: “~4.5.0”, “typescript”: “~2.2.0”, “webpack”: “~2.2.0”, “webpack-node-externals”: “^1.5.4”
But when running “ng build && ngc && webpack” I get this error message: Error: No module factory available for dependency type: ContextElementDependency at Compilation.addModuleDependencies (/www/dev2/front-end/node_modules/@angular/cli/node_modules/webpack/lib/Compilation.js:206:21)…
Thanks.
Edit: after digging more into the issue, it seems the template compiler don’t create ngfactory.ts files for some of my components. Can’t figure out why. It happens since webpack was installed.
I got this same error when I used
yarn
to install dependencies instead ofnpm install
. Cleaning node modules and runningnpm install
fixed the problem for me.I had a problem when the @angular/cli module version I had was 1.3.0. All the problems were solved when I ran the
npm i @angular/cli --save-dev
command. Try this and Please write a comment~👍@filipesilva Sorry I hadn’t seen your solution from the other issue. Changing
to
eliminated that error. I have other problems with routing so I can’t say for sure whether this has any bad consequences.
I had been getting this error:
After making the above change, I am getting this one instead:
I cleared node_modules, rebuilt project and some clean ups and now gone, so closing, regards