Skip to content

Yarn creates incompatible @ngtools/webpack/node_modules (AppModule is not an NgModule) #6425

@nhnb

Description

@nhnb
- [X] bug report -> please search issues before submitting
- [ ] feature request

There have been a number of reports about Angular 4 working with npm. But failing with the following error message on "ng build" when yarn has been used:
ERROR in AppModule is not an NgModule

Among the many differences in node_modules between npm and yarn, I traced the issue down to the folder node_modules/@ngtools/webpack/node_modules. It does not exist on npm install, but yarn creates it with loader-utils (version 1.1.0) and typescript (version 2.2.2).

Deleting this folder fixes the "AppModule is not an NgModule" error and the project can be compiled successfully.

Please note: The typescript version in that folder is 2.2.2. The instructions at Updating to 4.0.0 suggest to use typescript@latest, which results in ^2.3.3 in package.json

Versions.

  • @angular/cli: 1.0.4
  • node: 6.9.5 os: linux x64
  • @angular/animations, @angular/common, @angular/compiler, @angular/core, @angular/forms, @angular/http, @angular/platform-browser, @angular/platform-browser-dynamic, @angular/router and
    @angular/compiler-cli: 4.1.3
  • typescript: 2.3.3
  • npm: 3.10.10
  • yarn: 0.19.1

The log given by the failure.

ng build --prod --aot
Hash: f51dd13e0d7162822443                                                               
Time: 20451ms
chunk    {0} styles.96c0a658294179b6d7fc.bundle.css (styles) 281 bytes {3} [initial] [rendered]
chunk    {1} main.117d403616e3c6b9015d.bundle.js (main) 1.39 kB {2} [initial] [rendered]
chunk    {2} vendor.c85a90b3d399a6fd167d.bundle.js (vendor) 1.04 MB [initial] [rendered]
chunk    {3} inline.d05467de75134d5563b5.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in AppModule is not an NgModule

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/tmp/hisngyarn/src'
 @ ./src/main.ts 5:0-74
 @ multi ./src/main.ts

Mention any other details that might be useful.

package.json.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentseverity2: inconvenient

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions