Skip to content

Fix: Error: Emit attempted before angular webpack plugin initialization

  • by
  • 3 min read
What is Metadata? Types and benefits | Candid.Technology

Programming and development have become far easier than they used to be only a few years ago. However, random error messages and bugs are still an everyday issue for most programmers. That said, while most error messages are now pretty self-explanatory, you’ll come across a few that’ll leave you scratching your head occasionally. 

In this article, we’re talking about the “Error: Emit attempted before angular webpack plugin initialization” issue, its causes, and how to fix the problem. 


What causes the “Error: Emit attempted before angular webpack plugin initialization” issue?

The error message occurs when there’s an issue with the Angular Webpack plugin initialisation. Alternatively, you can also run into this error if the NGCC or Angular Compatibility Compiler fails to process the package properly. 

The Angular compiler also requires certain compiler options on initialisation. If these options aren’t present or are incorrectly set, you can run into this problem. 

Also read: Fix: Python setup.py egg_info did not run successfully


How to fix the “Error: Emit attempted before angular webpack plugin initialization” issue?

Here are three fixes you can try out.

Update your configuration files

One of the easiest solutions for the problem is to add the following line to your tsconfig.app.json file. 

"angularCompilerOptions": { "enableIvy": false }

Once done, restart your project and check to see if the error persists.


Upgrade your Typescript version

Using an older Typescript version, upgrading your Angular version can break things. Based on which version of Angular you’re using, update your package.json file accordingly. 

For Angular 15

"devDependencies": {
  ...
  "typescript": "~4.8.0"
}

For Anglular 14

"devDependencies": {
  ...
  "typescript": "~4.7.0"
}

If it doesn’t work, make sure to install the required version of Typescript before trying again. You can use this command. 

npm install typescript@"~[enter version number]" --save-dev

Upgrade your Node version

Last, upgrading your Node version has also been known to fix the problem. If you’re still running Node version 16 or lower, try upgrading to version 18 (LTS) to see if that fixes the problem. You can use the command given below. 

nvm install node --reinstall-packages-from=node
Top 7 IDEs and Text Editors to code Python, Java, C++, HTML and more

Also read: How to add a header file in Dev C++?

nv-author-image

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: [email protected].

>