Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):

Hello guys,
I am having this error for 2 days now and I can’t find a solution online. Maybe someone who already find a solution for this, please help. Thanks in advance.

./src/main.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Emit

./src/polyfills.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Emit

Error: Failed to initialize Angular compilation - Cannot read properties of null (reading ‘fileName’)

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

× Failed to compile.

Looks like something wonky with the node modules. Try:

  1. delete the node_modules folder
  2. delete package-lock.json
  3. clear your NPM cache: npm cache clean --force
  4. install again all dependencies: npm i

Otherwise this may have to be reported to the @ngtools owners by opening a GitHub issue here: Issues · angular/angular-cli · GitHub

Thanks for your response. I tried and follow the steps and now node_modules turned grey as if they are not part of the project.

Did you run the commands from inside your project folder?

1 Like

Yes, both inside and outside the project folder.

Does your project build? Is the node_modules folder empty after reinstalling dependencies?

1 Like

The project did not build and the node_modules folder not empty after reinstalling dependncies but it’s greyed out on mac as if its not activated but for windows its shows normal but again same error is there. It all starts when I add service for a contact form to be save in firebase. If in case I want to remove the services all will be working fine.

Sorry - I do not have any other advice (other than maybe try “turning it off and on again” on your Mac). As I said, you might try reporting the issue on GitHub so that the owners of ngtools can respond.

1 Like

Same problem here, it happened to me after I’ve installed ng2-toast and include it in the imports array, inside the app.module.

here are the messages:

./src/main.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.

./src/polyfills.ts - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
Error: Emit attempted before Angular Webpack plugin initialization.

Error: Failed to initialize Angular compilation - Importing unexpected symbol ɵɵinvalidFactory while compiling @angular/core

since then, I’ve tried update the @angular/core and @angular/cli,
I’ve tried an older version of toasty,
unfortunatelly, without success.