【发布时间】:2019-01-11 05:53:55
【问题描述】:
我正在尝试将我现有的 Angular 项目转换为使用 Angular Universal (https://universal.angular.io/)。我正在关注本教程:https://github.com/angular/angular-cli/wiki/stories-universal-rendering。我被困在第 3 步(构建捆绑包)的末尾。我的项目名称是“fundercat”。当我尝试运行时:
ng run fundercat:server
我得到错误:
Project 'dist/fundercat' could not be found in workspace.
按照教程,我在 app.module.ts 中修改了以下行:
@NgModule({
imports: [
// Modified this line:
BrowserModule.withServerTransition({appId: 'fundercat'}),
我在 angular.json 中添加了以下内容:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"fundercat": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
...
// added this block:
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/fundercat",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
}
}
知道我做错了什么吗?
【问题讨论】:
-
Project 'dist/fudercat' could not be found in workspace.fudercat 对吗? -
您将输出路径指定为“dist/fundercat”,但您的错误显示为“dist/fudercat”?检查您是否没有拼写错误,您粘贴的代码似乎没问题。
-
好收获!那是我报告错误时的错误。我确认我的代码中没有拼写错误。
-
可以查看
"outputPath": "dist/server"吗? -
用什么方法检查?教程显示应该是
"outputPath": "dist/your-project-name-server",,所以我设置为"outputPath": "dist/fundercat",。
标签: javascript angular server command-line-interface universal