Search code examples
angularangular-universalangular-seo

project name not found in angular


I am trying to convert my angular app to angular universal. I keep getting the error saying:

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

when I try to build the app using:

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"

I tried deleting the node_modules folder but I get the same error again. How to fix this?


Solution

  • You should use your own project name in build:client-and-server-bundles script:

    package.json

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