1

I want to upgrade my Angular 14 app to version 15, but I'm encountering an error message that says 'Cannot find name process.' I've already installed the @types/node package and added 'node to the types field in my tsconfig.json file, but the error persists. I've tried multiple solutions I found, but none of them have worked for me. I even tried reloading the window in VScode.

TS2591: Cannot find name 'process'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.

Node veriosn: 18.10.0 npm: 8.19.2

package.json

{
  "name": "workplace",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "jest",
  },
  "private": true,
  "dependencies": {
    "@angular-builders/jest": "^15.0.0",
    "@angular/animations": "15.2.1",
    "@angular/common": "15.2.1",
    "@angular/compiler": "15.2.1",
    "@angular/core": "15.2.1",
    "@angular/forms": "15.2.1",
    "@angular/platform-browser": "15.2.1",
    "@angular/platform-browser-dynamic": "15.2.1",
    "@angular/router": "15.2.1",
    "@ngxs/store": "^3.7.6",
    "@types/lodash-es": "^4.17.7",
    "date-fns": "^2.29.3",
    "dotenv": "^16.0.3",
    "dotenv-webpack": "^8.0.1",
    "json5": "^2.2.3",
    "lodash-es": "^4.17.21",
    "ngx-cookie-service": "^15.0.0",
    "node-fetch": "^2.6.8",
    "printj": "^1.3.1",
    "rxjs": "7.8.0",
    "tslib": "2.5.0",
    "zone.js": "0.11.8"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "^15.0.0",
    "@angular-devkit/build-angular": "^15.2.4",
    "@angular/cli": "15.2.1",
    "@angular/compiler-cli": "15.2.1",
    "@cypress/schematic": "^2.5.0",
    "@ngxs/devtools-plugin": "^3.7.6",
    "@openapitools/openapi-generator-cli": "2.5.2",
    "@testing-library/angular": "12.1.2",
    "@testing-library/jest-dom": "5.16.5",
    "@types/jest": "29.4.2",
    "@types/node": "^18.15.3",
    "eslint-plugin-ngxs-style-guide": "^3.0.0",
    "jest": "29.5.0",
    "jest-preset-angular": "13.0.0",
    "replace-in-file": "^6.3.5",
    "typescript": "4.9.5"
  },
  "peerDependencies": {
    "@angular/elements": "15.2.1"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "types": ["node"]
  }
}

block code, which I used process:

updateTask(
    key: string,
    paramsObject: obj,
    body: unknown = {}
  ): Observable<unknown> {
    const params = new HttpParams({ fromObject: paramsObject });
    return this.http.post(
      `${process.env['SERVICES_URL']}/task/${key}?`,
      body,
      { params }
    );
  }
vsam
  • 533
  • 3
  • 23
  • What `node` and `npm` versions are you using? – Harun Yilmaz Mar 20 '23 at 11:05
  • @Huran Node veriosn: 18.10.0 npm: 8.19.2 – vsam Mar 20 '23 at 11:08
  • Does this answer your question? [typescript error - cannot find name 'process'](https://stackoverflow.com/questions/53529521/typescript-error-cannot-find-name-process) – Harun Yilmaz Mar 20 '23 at 11:09
  • unfortunately no! I saw this answer already – vsam Mar 20 '23 at 11:12
  • Oh, I see... I think `process` is available on the server side, not the client/browser side. If you want to use environment variables, you need to use Angular environment files. You can see that the browser's environment depends on the machine it runs on, so it doesn't make sense to use the process environment. – Harun Yilmaz Mar 20 '23 at 11:17

0 Answers0