question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting NODE_ENV to "production" without --minify

See original GitHub issue

I want to use the replaceNodeEnv flag together with treeshake to be able to create separate build outputs for production and development. To insert additional checks and console.logs only if the library user is in development. But the env field seems to not be able to overwrite the default "development" for non-minified builds. I don’t want to use --minify, so that the output code is easier to inspect. Is there any other way to set the NODE_ENV to "production", so that it’s respected by replaceNodeEnv?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
egoistcommented, Jul 30, 2022

Isn’t this the same as the env field in the tsup config file? I’ve tried it, but with no luck as well. I’ll make a repro if it’s something that is supposed to work already

yes please

0reactions
thetarnavcommented, Oct 12, 2022

I’ve stumbled on this issue recently again, but this time I was able to walk around it by defining esbuildOptions instead:

esbuildOptions(options) {
  options.define = {
    ...options.define,
    'process.env.NODE_ENV': '"production"',
  };
},

Here is the “fixed” example: https://stackblitz.com/edit/tsup-treeshake-development-issue-qobqkw

Read more comments on GitHub >

github_iconTop Results From Across the Web

You are currently using minified code outside of NODE_ENV ...
i created react app and i need to have 3 node_env: "start": "cross-env NODE_ENV=development webpack serve", "build-accept": "cross-env ...
Read more >
NODE_ENV related warning when used in minified bundle #534
You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of ...
Read more >
Concatenation and Minification | Laravel Mix Documentation
Once again, the minification will only take place during a production build. ( export NODE_ENV=production ). There is no need to call mix.combine(['one.js',...
Read more >
Express Tutorial Part 7: Deploying to production
We can remove stack traces in error pages by setting the NODE_ENV environment variable to production (it is set to 'development' by default) ......
Read more >
Performance Best Practices Using Express in Production
Set NODE_ENV to “production ” · Ensure your app automatically restarts · Run your app in a cluster · Cache request results ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found