简体   繁体   中英

WARNING: NODE_ENV value of 'test ' did not match any deployment config file names

Receiving this warning on running a node.js app despite all testing suggesting everything fine.

I've included the below code in my app to fault find:

console.log('NODE_ENV: ' + config.util.getEnv('NODE_ENV')); console.log('NODE_CONFIG_DIR: ' + config.util.getEnv('NODE_CONFIG_DIR'));

And the output in terminal is:

NODE_ENV: test NODE_CONFIG_DIR: C:\Users\[username]\OneDrive - [Company Name]\Documents\projects\[project name]\server\config

Terminal Output

终端输出

Inside that folder (verified by copying and pasting the URI into explorer) are two files:

default.json test.json

Config folder contents

配置文件夹内容

That seems to be correct to me, I've checked the guidance and can't see anything out, checked google hits and the answers don't appear to relate. Any help would be greatly appreciated.

Though the mentioned package in the accepted answer resolves the issue, it is good not to get more dependencies in your project's package.json when the same can be sorted with a simple tweak as below: -

In your package.json file by omitting the space before && . This will detect the environment(s) correctly without extra space after the name.

在此处输入图片说明

Quick answer:

Use something like cross-env on windows environments: npm cross-env

From what I can find, this appears to fall into the 'Windows issues with NODE_ENV' category. Setting the NODE_ENV separately, prior to starting the app results in the environment working correctly; any manipulation of NODE_ENV inside a package.json script on its own results in failure.

This answer on another question led me to the package cross-env, and when implemented as identified in the answer resolves the issue.

I solved this problem Just adding a space to the end of filename: test.json ==> test .json

Remember that there is always a space behind values in environmental variables!

If anyone else has the same error be sure to run the jest command from your project's root directory if you directly use jest cli instead of an npm script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM