在 angular 中找不到项目名称

project name not found in angular

我正在尝试将我的 angular 应用程序转换为 angular 通用应用程序。我不断收到错误消息:

Project 'my-app' could not be found in Workspace.

当我尝试使用以下方法构建应用程序时:

npm run build:client-and-server-bundles && npm run webpack:server

app.module.ts:

BrowserModule.withServerTransition({appId: 'techstack21-angular'}),

Angular.json:

"server": {
  "builder": "@angular-devkit/build-angular:server",
  "options": {
    "outputPath": "./dist/techstack21-angular",
    "main": "src/main.server.ts",
    "tsConfig": "src/tsconfig.server.json"
  }
},

tsconfig.app.json:

"compilerOptions": {
  "outDir": "../dist/techstack21-angular",
  "module": "es2015",
  "types": ["node"],
  "typeRoots": [
    "node_modules/@types"
  ],
},

Package.json:

 "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:ssr": "node dist/server",
    "build:client-and-server-bundles": "ng build --prod && ng run my-app:server",
    "webpack:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve": "node server.js"

我尝试删除 node_modules 文件夹,但我再次遇到同样的错误。如何解决这个问题?

您应该在 build:client-and-server-bundles 脚本中使用您自己的项目名称:

package.json

"build:client-and-server-bundles": "ng build --prod && ng run my-app:server",
                                                              ^^^^^^
                                                  replace with your projectName