1

I am struggling with the following error:

error 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.

baseUrl: process.env.TEST

// environment.prod.ts

import 'dotenv/config';

export const environment = {
    production: true,
      baseUrl: process.env.TEST
    };

//.env

TEST=whatever

I've already installed @types/node and dotenv, the problem is the IDE on typescript files is telling me there is something wrong with TEST, what am I missing?

1
  • 1
    Seems like your IDE is simply kidding you. If you have installed dotenv and @types/node, tsc environment.prod.ts shouldn't give you any error. Commented Sep 22, 2022 at 14:54

1 Answer 1

2

Its not enough to install dotenv package, it's types and use it right after with process.env.TEST

You also have to configure your dotenv package in App.ts or any root file of an application you have

something like this:

dotenv.config({ path: __dirname + `/../.production.env}` })
Sign up to request clarification or add additional context in comments.

5 Comments

Excuse me sir, there is no app.ts on my app. also i cannot set the code you told me on environment.ts, thanks
what's your root file? it can be index.js also
would you mind to be more explicit with where should I place your code? I think i am doing it properly but it is the first time i am on NodeJS... thank you
The question is I have to set it on a .ts script. On .js file no problem about it
what the problem was tho?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.