-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library Mode replaces "process.env.NODE_ENV" #3229
Comments
Please try to apply this workaround: #3077 (comment) |
@Shinigami92 i saw this issue before opening my bug report, but this workaround isn't working as i have a variable not a string. |
And is |
@Shinigami92 i think this would work, but i would still consider this as a bug. i hate modifying code (make it harder to read) to match a build tool and i don't think this should happen in library mode. |
I didn't say you should close this issue 😅 |
Maybe we should close this one duplicate of #3176 |
Nope, use process.env['NODE_ENV'] in library code, process.env['NODE_ENV'] will be preserved in your application code, this is expected behavior because process in undefined in browser. @Shinigami92 In this case, you should declare replace plugin in your appliation like this. replace({
'process.env.NODE_ENV': JSON.stringify('production'),
`process.env['NODE_ENV']`: JSON.stringify('production'),
})
` |
I was able to preserve define: {
'process.env.NODE_ENV': 'process.env.NODE_ENV',
}, EDIT: Actually this throws in serve mode, so you have to conditionally define it in production mode only: import { defineConfig } from 'vite';
export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
const config = {
// ...
};
if (isProd) {
config.define = {
'process.env.NODE_ENV': 'process.env.NODE_ENV',
};
}
return config;
}); |
Hello, I"ve read all the related issue but I don't understand how to solve it for external libraries, in my case js-ipfs:
|
I got this fixed using: optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: "globalThis",
// my fix
"globalThis.process.env.NODE_ENV": "development"
},
} |
Hello, I still haven't solved this problem. Is there any other solution |
Describe the bug
process.env.NODE_ENV
gets replaced and removes code in library mode. This is an undesirable behaviour as i want to have this check in the project i'm going to import the library.Reproduction
if build with
vite build
using this config:it will become:
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager: npm
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: