Ng serve throwing @angular/core/core has no exported member 'eeFactoryDef'

A lot of people saying the solution here is to simply "delete your node_modules". This may or may not work.


To understand why that is the case, you need to understand why you're getting this error. This is caused by a breaking change in Angular where code generated using angular version x is not compatible with angular version y (happens in multiple versions, I'm currently getting it between 10 and 13). The eeFactoryDef is a method generated by Angular when your source is compiled. The name of this method has changed over the years. So the delete node_modules works because it's assuming that you've just upgraded angular and you have an old version still hanging about.

This also explains why there are so many different answers to this question. The angular incompatibility could be in your code or one of its dependancies. All the people saying "I get this in x library" are basically because of this underlying problem.


But, you can also get this issue if you have a dependency issue. The easiest way to diagnose this problem is to run npm ls @angular/core. This will list all the library dependencies that link to this lib, for example I get:

`-- UNMET PEER DEPENDENCY @angular/[email protected]

npm ERR! peer dep missing: @angular/core@~11.2.13, required by [email protected]
npm ERR! peer dep missing: @angular/[email protected], required by [email protected]
npm ERR! peer dep missing: @angular/core@^11.0.5, required by [email protected]
npm ERR! peer dep missing: @angular/core@^6.0.0 || ^7.0.0 || ^8.0.0, required by [email protected]

In this scenario you need to upgrade the conflicting libraries so that they all use the same (or a compatible) version of angular (and no amount of deleting and re-adding of node_modules will make any difference).


Another problem that has this as a symptom is the Ivy compiler. Again, this can produce an incompatible build between libraries and applications. The solution here depends on where the incompatibility lies. If you lib is not Ivy but your application is, then you can either opt out of Ivy

tsconfig.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "angularCompilerOptions": {
    "enableIvy": false
  }
}

Or run ngcc in a postinstall event:

package.json

{
   "scripts": {
       "postinstall": "ngcc"
   }
}

I ran into this after updating some packages (including Angular from 8 to 9), then downgrading again.

The solution was to nuke the node_modules folder and then do a fresh npm install.


I'm getting the same error. I'm using Angular 9.7.1, I first tried to delete the node_modules and npm install but it didn't work so I finally fixed it adding this to the tsconfig.json:

"compilerOptions":{
 [...]
 "paths": {
      "@angular/*": ["./node_modules/@angular/*"]
    }
}

In addition to the reasons/solutions previously shared, another reason this could happen is if npm packages are incompatible with your current Angular version.

For example, I got these after running npm i primeng. NPM installed the most recent version (v12), but I was only running ng11.

In my case, the solution was to upgrade Angular, but another solution would be to downgrade the npm package.

Tags:

Angular