process is not defined in nx angular monorepo

Discussão em 'Angular' iniciado por Shahan, Janeiro 3, 2025.

  1. Shahan

    Shahan Guest

    I created a new nx angular monorepo and when trying to view the environment variables using this code

    export class AppComponent implements OnInit {
    ngOnInit() {
    console.log(process.env);
    }
    }


    I get this error in the console.


    ERROR ReferenceError: process is not defined
    ​

    Adding @types/node to my package.json and adding types:["node"] to my tsconfig.app.json did not work and I'm not sure what else to try.

    Package.json:

    {
    "name": "@process-test/source",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {},
    "private": true,
    "dependencies": {
    "@angular/animations": "~19.0.0",
    "@angular/common": "~19.0.0",
    "@angular/compiler": "~19.0.0",
    "@angular/core": "~19.0.0",
    "@angular/forms": "~19.0.0",
    "@angular/platform-browser": "~19.0.0",
    "@angular/platform-browser-dynamic": "~19.0.0",
    "@angular/router": "~19.0.0",
    "rxjs": "~7.8.0",
    "zone.js": "~0.15.0"
    },
    "devDependencies": {
    "@angular-devkit/build-angular": "~19.0.0",
    "@angular-devkit/core": "~19.0.0",
    "@angular-devkit/schematics": "~19.0.0",
    "@angular/cli": "~19.0.0",
    "@angular/compiler-cli": "~19.0.0",
    "@angular/language-service": "~19.0.0",
    "@eslint/js": "^9.8.0",
    "@nx/angular": "20.3.0",
    "@nx/devkit": "20.3.0",
    "@nx/eslint": "20.3.0",
    "@nx/eslint-plugin": "20.3.0",
    "@nx/jest": "20.3.0",
    "@nx/js": "20.3.0",
    "@nx/playwright": "20.3.0",
    "@nx/web": "20.3.0",
    "@nx/workspace": "20.3.0",
    "@playwright/test": "^1.36.0",
    "@schematics/angular": "~19.0.0",
    "@swc-node/register": "~1.9.1",
    "@swc/core": "~1.5.7",
    "@swc/helpers": "~0.5.11",
    "@types/jest": "^29.5.12",
    "@types/node": "^18.16.9",
    "@typescript-eslint/utils": "^8.13.0",
    "angular-eslint": "^19.0.2",
    "eslint": "^9.8.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-playwright": "^1.6.2",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-preset-angular": "~14.4.0",
    "nx": "20.3.0",
    "prettier": "^2.6.2",
    "ts-jest": "^29.1.0",
    "ts-node": "10.9.1",
    "tslib": "^2.3.0",
    "typescript": "~5.6.2",
    "typescript-eslint": "^8.13.0"
    }
    }


    tsconfig.app.json:

    {
    "extends": "./tsconfig.json",
    "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "types": ["node"]
    },
    "files": ["src/main.ts"],
    "include": ["src/**/*.d.ts"],
    "exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
    }

    Continue reading...

Compartilhe esta Página