process.env variables are not resolved

I have defined my NODE_ENV and PORT in my Run/Debug Configuration, it is working fine, "problem" is that i'm getting a warning that NODE_ENV or PORT is not resolved.

 



Is this a common issue or did i missed a part of the configuration?

0
13 comments

Variables you have defined in run configuration are only available in runtime, they can't be resolved during static code analysis

0

I tried various statement suppressions to prevent this warning, in the end, the best solution I found was to add a globals comment for process

 

    /* global process */

-1

This problem occurs because the Node.js Core library is either missing or incorrectly referenced. It can be resolved easily by following these steps:

 

1. Open the WebStorm settings window

 

2. Expand "Languages & Frameworks" and click on "Node.js and NPM"

 

3. Click on the + icon on the right to install a new Node.js module

 

4. Search for "node-core-lib" (without the quotation marks), after searching only one item should remain. Click on it to select it and then click on the "Install Package" button in the lower left corner of the window to install the "node-core-lib" package.

 

5. After installation close the "Available Packages" window, then click "OK" or "Apply" in the settings window. All global/process/etc. references should now resolve to the correct packages and no longer show the "reference unresolved" warning.

 

 

:D :D

 

 

 

4

I haven't got the last screenshot in the last step? - are you creating a "config.js" file in your project folder and putting this row in it? 

0

FYI: since 2019.1, environment variables defined in Node.js run configuration are resolved/completed in editor (https://youtrack.jetbrains.com/issue/WEB-37123)

2020.1 adds support for variables defined in .env (https://youtrack.jetbrains.com/issue/WEB-42784) and nodemon.json (https://youtrack.jetbrains.com/issue/WEB-40015)

1

I've added `.env` to the root of a project, there wrote:

PORT = "3000"

but `process.env.PORT` still raises "Unresolved variable PORT".

Could you, please, point me what am I doing wrong?

 

IntelliJ IDEA 2020.1 (Ultimate Edition)
Build #IU-201.6668.121, built on April 8, 2020

0

I've installed Env-Plugins:

restarted IDEA and now IDEA shows PORT value from `.env`, when I click on `PORT`, I'm forwarded to the `.env` file, but IDEA still marks `PORT` as unresolved:

2

Hi Mike, 

I had resolved my problem by just passing a parameter to my bundler in the CLI. I've noticed, though, is the project there is an ignore line for ".ENV" files, which took me to the authors of such plug-ins, which I've installed. From your links, the second looks interesting, and I will try it. As for the first one, though, I can confirm that this gives only the syntax hightlihgt for .evn files, nothing more. I would advise you to try the "dotenv" npm package. It reads ".env" configurations and also is quite famous for that purpose.  You can find a good tutorial about dealing with environment variables with ".env " file on Medium, for example, explaining in detail with examples. 

1

Hi Vladimir,

thanks for sharing this info, I'll check the dotenv module.

0

Hi Mike, 

I hope you'll manage it in the best way! 

0

I'm inheriting a project where if I run "yarn run dev" the process variable is defined but when I try to run through Webpack debugger it isn't defined. It is running "vue-cli-service serve". I tried adding "--mode development" but it didn't help.

0

Please sign in to leave a comment.