Solveduniversal starter Error: No module factory available for dependency type: ContextElementDependency

This error shows on a fresh install of 6.0.0 (npm i && ng serve):

Error: No module factory available for dependency type: ContextElementDependency
    at addDependency (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:407:12)
    at iterationOfArrayCallback (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:88:3)
    at addDependenciesBlock (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:423:5)
    at iterationOfArrayCallback (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:88:3)
    at addDependenciesBlock (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:426:5)
    at Compilation.processModuleDependencies (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:434:4)
    at afterBuild (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:556:15)
    at buildModule.err (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:600:11)
    at callback (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:358:35)
    at module.build.error (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:394:12)
    at resolveDependencies (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\ContextModule.js:233:4)
    at ContextModule.result.resolveDependencies (C:\...\universal-starter\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:476:25)
    at ContextModule.build (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\ContextModule.js:158:8)
    at Compilation.buildModule (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:362:10)
    at factory.create (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\Compilation.js:583:14)
    at hooks.afterResolve.callAsync (C:\...\universal-starter\node_modules\@angular-devkit\build-angular\node_modules\webpack\lib\ContextModuleFactory.js:150:16)
C:\...\universal-starter\node_modules\neo-async\async.js:14
    throw new Error('Callback was already called.');
    ^

Error: Callback was already called.
    at throwError (C:\...\universal-starter\node_modules\neo-async\async.js:14:11)
    at C:\...\universal-starter\node_modules\neo-async\async.js:2805:7
    at process._tickCallback (internal/process/next_tick.js:150:11)
13 Answers

✔️Accepted Answer

You can get this working off a project that has webpack already installed by doing:
1.npm ls webpack
you should have the output

ng-universal-demo@0.0.0 /home/fabian/Documents/universal-starter
├─┬ @angular-devkit/build-angular@0.6.0
 └── webpack@4.6.0
└── webpack@4.8.1
  1. npm uninstall webpack then npm ls webpack
    This will uninstall all copies of webpack so the output should be
fabian@fabian-desktop:~/Documents/universal-starter$ npm ls webpack
ng-universal-demo@0.0.0 /home/fabian/Documents/universal-starter
└── (empty)
  1. Remove package-lock.json and node_modules then npm install and finally npm ls webpack
    Which should then have the output
fabian@fabian-desktop:~/Documents/universal-starter$ npm ls webpack
ng-universal-demo@0.0.0 /home/fabian/Documents/universal-starter
└─┬ @angular-devkit/build-angular@0.6.0
  └── webpack@4.6.0

If successful then you can test it with npm run build:ssr if this succeeds then you're golden.
As an alternative you can simply edit your package.json to remove webpack, then remove your package-lock.json and node_modules then do a npm install and you should be good to go


I understand your frustration but I only have so much time in a day to maintain things around here.
I've investigated this issue and the solution i've provided is the best that's currently available.

Related Issues:

36
universal starter How to deploy Angular Universal to production (port 80)
The @kalyan1102 answer is correct After make the app how to deploy it? I see that on package.json th...
13
universal starter Can't get current request (or more specifically cookies)
Fixed by adding empty array to deps for the provider: Hi again ! Going deeper and deeper in the use ...
13
universal starter Error: No module factory available for dependency type: ContextElementDependency
You can get this working off a project that has webpack already installed by doing: 1.npm ls webpack...
11
universal starter How add a translate module to universal starter?
So I lost half a day figuring out how to use ngx-translate with universal-starter therefore find out...
6
universal starter not implemented in Parse5DomAdapter: getElementsByTagName
Okay just in case anyone else lands here and needs this Hi I may be running away with things that ar...
3
universal starter How to set meta data in index.html
@nicky-lenaers My solution should work on server-side at leats it works for me Here i have seen angu...