ERROR in Error: ***Module is not an NgModule
引入一个打包的模块时报了这个个错:
$ rimraf out Done in 16.81s. lerna ERR! build Errored while running script in 'map' lerna ERR! execute callback with error lerna ERR! Error: Command failed: yarn run build lerna ERR! warning package.json: License should be a valid SPDX license expression lerna ERR! warning ../../../package.json: No license field lerna ERR! lerna ERR! ERROR in Error: Ng2WindowModule is not an NgModule lerna ERR! at _getNgModuleMetadata (/Users/machan/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@angular/compiler-cli/src/ngtools_impl.js:140:15) lerna ERR! at _extractLazyRoutesFromStaticModule (/Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@angular/compiler-cli/src/ngtools_impl.js:109:26) lerna ERR! at /Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@angular/compiler-cli/src/ngtools_impl.js:129:27 lerna ERR! at Array.reduce (<anonymous>) lerna ERR! at _extractLazyRoutesFromStaticModule (/Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@angular/compiler-cli/src/ngtools_impl.js:128:10) lerna ERR! at Object.listLazyRoutesOfModule (/Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@angular/compiler-cli/src/ngtools_impl.js:53:22) lerna ERR! at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@angular/compiler-cli/src/ngtools_api.js:91:39) lerna ERR! at AotPlugin._getLazyRoutesFromNgtools (/Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@ngtools/webpack/src/plugin.js:240:66) lerna ERR! at _donePromise.Promise.resolve.then.then.then.then.then (/Users/**/Desktop/workspace/office/trunk-web2.5/packages/ng-apps/map/node_modules/@ngtools/webpack/src/plugin.js:493:24) lerna ERR! at <anonymous> lerna ERR! error Command failed with exit code 1.
这个错跟AppModule is not a NgModule的原因不一样。
试了很多方法,最后在tsconfig.json里面添加
{
...
"compilerOptions": {
...
"paths": {
...
"@**/ng2-window": ["../node_modules/@**/ng2-window/src"],
"@**/ng2-property": ["../node_modules/@**/ng2-property/src"],
"@**/ng-common": ["../node_modules/@**/ng-common/src"],
"@**/ng-core": ["../node_modules/@**/ng-core/src"]
}
},
"exclude": [
...
]
}
通过path的设置,来指定调用的模块路径。
------------------------------------------------------
AppModule is not a NgModule的报错,原因很多是跟typescript或者angular的版本有关。