Support Forums

How to set NPM_FLAGS environment variable properly?

I set NPM_FLAGS to --only=prod --verbose from UI, but when building, i’ve got following warning:

2:48:54 PM: npm WARN invalid config only="prod --verbose" set in command line options
2:48:54 PM: npm WARN invalid config Must be one of: null, dev, development, prod, production

How to set NPM_FLAGS properly?

hi there @el7cosmos and welcome to our community!

This is the line in our build scripts when we use them:

I didn’t go to deep into why that is happening since I discovered that --verbose --only=prod (no explicit quotes in my settings, just for clarity here!) seemed to work better for me - could you let me know if that works better for you too?

It didn’t throw a warning, but no verbose output.

I try in my local following command:

npm install "--only=prod --verbose"

throws same warning, and

npm install "--verbose --only=prod"

didn’t have verbose information.

I think thats because either shell or npm treat those as 1 argument instead of 2 or multiple

Hey @el7cosmos, this seems like a bug to me. When I set NPM_FLAGS to either --verbose or --only=prod seems to work, but setting the variable to both doesn’t seem to work. I’ve opened an issue here (https://github.com/netlify/build-image/issues/496) and we can let you know if/when there’s movement on it. Or if this is urgent for you, I’m sure the build team would love a PR! :slight_smile:

1 Like

Hey folks :wave:

For anyone following this post, just wanted to let you know that thanks to an awesome contribution to our OSS build-image repo, this issue has been fixed and rolled out to our xenial and focal releases.

Thank you all!

1 Like