Angular 中的 PWA 支持抛出 node_modules/@angular/service-worker/service-worker.d.ts,发现版本 4,预期 3 错误
PWA support in Angular throws node_modules/@angular/service-worker/service-worker.d.ts, found version 4, expected 3 error
我正在将 PWA 集成到我的 Angular 项目中。在 app.module.ts
中注册 ServiceWorkerModule
时出现错误
app.module.ts
@NgModule({
imports: [
...
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
]
})
当我 运行 ng build --prod
给我这个错误时
ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/app/webel/src/main/webapp/webel/src'
ERROR in Error: Metadata version mismatch for module /app/webel/src/main/webapp/webel/node_modules/@angular/service-worker/service-worker.d.ts, found version 4, expected 3
at StaticSymbolResolver.getModuleMetadata (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:25616:34)
at StaticSymbolResolver._createSymbolsOf (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:25404:46)
at StaticSymbolResolver.getSymbolsOf (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:25385:14)
at /app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:24241:30
at Array.forEach ()
at extractProgramSymbols (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:24240:79)
at AotCompiler.analyzeModulesAsync (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:23796:47)
at CodeGenerator.codegen (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler-cli/src/codegen.js:32:14)
at Function.NgTools_InternalApi_NG_2.codeGen (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler-cli/src/ngtools_api.js:73:30)
at _donePromise.Promise.resolve.then (/app/webel/src/main/webapp/webel/node_modules/@ngtools/webpack/src/plugin.js:428:58)
at
at process._tickCallback (internal/process/next_tick.js:160:7)
我使用的版本如下,
"@angular/cli": "^1.7.3"
"ng-pwa-tools": "0.0.15"
"@angular/service-worker": "^6.0.1"
"@angular/compiler": "^4.4.4"
如有任何帮助,我们将不胜感激。
完全迁移到 angular 6.0 解决了这个问题。尽管 rxjs
在 6.0 中有一些重大变化,这可以通过迁移到最新版本来解决,也可以通过添加 rxjs-compat
(Backword 兼容性)
立即修复
我正在将 PWA 集成到我的 Angular 项目中。在 app.module.ts
ServiceWorkerModule
时出现错误
app.module.ts
@NgModule({
imports: [
...
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
]
})
当我 运行 ng build --prod
给我这个错误时
ERROR in ./src/main.ts Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/app/webel/src/main/webapp/webel/src' ERROR in Error: Metadata version mismatch for module /app/webel/src/main/webapp/webel/node_modules/@angular/service-worker/service-worker.d.ts, found version 4, expected 3 at StaticSymbolResolver.getModuleMetadata (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:25616:34) at StaticSymbolResolver._createSymbolsOf (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:25404:46) at StaticSymbolResolver.getSymbolsOf (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:25385:14) at /app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:24241:30 at Array.forEach () at extractProgramSymbols (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:24240:79) at AotCompiler.analyzeModulesAsync (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler/bundles/compiler.umd.js:23796:47) at CodeGenerator.codegen (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler-cli/src/codegen.js:32:14) at Function.NgTools_InternalApi_NG_2.codeGen (/app/webel/src/main/webapp/webel/node_modules/@angular/compiler-cli/src/ngtools_api.js:73:30) at _donePromise.Promise.resolve.then (/app/webel/src/main/webapp/webel/node_modules/@ngtools/webpack/src/plugin.js:428:58) at at process._tickCallback (internal/process/next_tick.js:160:7)
我使用的版本如下,
"@angular/cli": "^1.7.3"
"ng-pwa-tools": "0.0.15"
"@angular/service-worker": "^6.0.1"
"@angular/compiler": "^4.4.4"
如有任何帮助,我们将不胜感激。
完全迁移到 angular 6.0 解决了这个问题。尽管 rxjs
在 6.0 中有一些重大变化,这可以通过迁移到最新版本来解决,也可以通过添加 rxjs-compat
(Backword 兼容性)