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

4

19

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

Terminal Output

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

default.json test.json

Config folder contents

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.

Manque answered 19/2, 2019 at 15:44 Comment(0)
V
28

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.

enter image description here

Vyborg answered 10/4, 2020 at 6:36 Comment(0)
M
1

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

Mcsweeney answered 23/8, 2022 at 9:42 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hate
M
0

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.

Manque answered 20/2, 2019 at 14:21 Comment(0)
C
0

I am using docker and when running set NODE_ENV=production&& node build/src/server.js (npm start script in package.json) I was getting the error

WARNING: NODE_ENV value of 'production' did not match any deployment config file names.
WARNING: See https://github.com/node-config/node-config/wiki/Strict-Mode
WARNING: No configurations found in configuration directory:/usr/src/app/config
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
/usr/src/app/node_modules/config/lib/config.js:179
    throw new Error('Configuration property "' + property + '" is not defined');

The root cause of the issue was that the config folder inside the root folder was not being copied to the docker container. So by adding the COPY command in the docker file (COPY ./config ./config) I was able to get it to work.

FROM node:lts-alpine3.16 as build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --silent
COPY . ./
#RUN rm -rf ./.local
#COPY .env.production ./.env
RUN npm run build
RUN ls -d "./build"

FROM node:lts-alpine3.16 as production
ARG NODE_ENV=production
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci --only=production
COPY ./config ./config                      <<<<<<< HERE
COPY --from=build /usr/src/app/build ./build
COPY ./.env.production ./.env
ENV NODE_ENV=production
RUN ls "./build"
CMD ["npm", "start"]
Crap answered 9/3, 2023 at 0:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.