当我尝试在我的项目中使用Ivy + Angular Universal时,出现错误。
仅当我使用Ivy模式时(当我在tsconfig.app.json
中将enableIvy
设置为false时,我可以成功构建我的应用程序),才会出现此错误。
以下是重现问题的步骤:
1. 新建一个Ivy项目
ng new test-angular --enableIvy
2. 添加Angular Universal
ng add @nguniversal/express-engine --clientProject test-angular
3. 当我执行ng build时,出现错误
ERROR in Node does not exist: "path_to/node_modules/@nguniversal/express-engine"
我的ng --version输出结果为:
Angular CLI: 8.1.0
Node: 10.15.3
OS: win32 x64
Angular: 8.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router
Package Version
--------------------------------------------------------------------
@angular-devkit/architect 0.801.0
@angular-devkit/build-angular 0.801.0
@angular-devkit/build-optimizer 0.801.0
@angular-devkit/build-webpack 0.801.0
@angular-devkit/core 8.1.0
@angular-devkit/schematics 8.1.0
@ngtools/webpack 8.1.0
@nguniversal/express-engine 8.1.1
@nguniversal/module-map-ngfactory-loader 8.1.1
@schematics/angular 8.1.0
@schematics/update 0.801.0
rxjs 6.4.0
typescript 3.4.5
webpack 4.35.2
如果我删除
main.server.ts
文件中的这些行(在步骤2中生成的文件),则会发生以下情况。export { ngExpressEngine } from "@nguniversal/express-engine";
export { provideModuleMap } from "@nguniversal/module-map-ngfactory-loader";
命令
ng build
和ng serve
可行,但我仍然不能使用SSR(npm run serve:ssr
失败了,因为provideModuleMap is not a function
,我猜是因为我删除的那一行导致的...)。谢谢 =)