我遵循了这个关于使用 Angular Universal 进行服务器端渲染的精彩教程 https://angularfirebase.com/lessons/server-side-rendering-firebase-angular-universal/
但是当运行npm run build:ssr && npm runserve:ssr
时,我收到以下错误:
不知何故,它无法识别我在 tsconfig.json
文件中定义的路径。
tsconfig.json
文件:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"paths": {
"@auth/*": [
"src/app/auth/*"
],
"@core/*": [
"src/app/core/*"
],
"@entities/*": [
"src/app/entities/*"
],
"@shared/*": [
"src/app/shared/*"
],
"@env/*": [
"src/environments/*"
],
"@reducers/*": [
"src/app/reducers/*"
],
}
}
}
最佳答案
我也遇到了同样的问题。我的 tsconfig.server.json 具有参数“baseUrl”:“.”。它覆盖 tsconfig.json 参数“baseUrl”:“./”。我刚刚将其删除,现在可以正常使用了
tsconfig.server.json 之前
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"outDir": "../out-tsc/app-server",
"baseUrl": "."
},
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
}
tsconfig.server.json 之后
{
"extends": "./tsconfig.app.json",
"compilerOptions": {
"outDir": "../out-tsc/app-server",
},
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
}
关于Angular 7 Universal - 无法解析路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53690541/