Can't start Angular application

Viewed 1633

Within the last few days, we have been encountering the following errors (and there doesn't seem to be match find in Google search):

npm start

ng serve

Compiling @angular/core : es2015 as esm2015
Error: Error on worker #1: TypeError: compiler_1.createMayBeForwardRefExpression is not a function

Any ideas why or workaround?

5 Answers

This error is caused by the version mismatch for most Angular framework packages(like core, common, compiler) with @angular/compiler-cli and @angular/language-service.

You should always use the same versions of these packages. Try using "^" with the version number.

As @a_tk explained, that is the usual issue here.

You need edit your package.json file and search for those packages (angular) and use the caret(^) instead of tilde(~) before the package version, example:

From this:

"@angular/cli": "~12.0.1",

To this:

"@angular/cli": "^12.2.0",

Then, to avoid related issues, I recommend delete node_modules directory and package-lock.json file and run:

npm i

I hope this help others.

Try to upgrade your global typscript package

npm install -g typescript@latest

Changing the package.json dependency as below resolved the issue for me

"@angular/compiler": "12.2.13", to "@angular/compiler": "^12.2.13",

Both answers from @a_tk and @manuelpgs could/should resolve the issue but most important is :

  • If you delete node_modules folder make sure you delete package-lock.json as well because if you dont you might spend hours on debugging versions (like silly me) and will not help you as long as locked file is present your versions might mismatch.

Using ng update you might shorten process to see what needs to update to what version. There might be additional packages which don't provide 'ng update' capabilities that are outdated but it might help solving issue.

Related