Skip to content
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

vite forcibly replaced process.env.NODE_ENV as mode option #8210

Closed
7 tasks done
maxming2333 opened this issue May 18, 2022 · 0 comments · Fixed by #8283
Closed
7 tasks done

vite forcibly replaced process.env.NODE_ENV as mode option #8210

maxming2333 opened this issue May 18, 2022 · 0 comments · Fixed by #8283

Comments

@maxming2333
Copy link

maxming2333 commented May 18, 2022

Describe the bug

When I write the following code in the code

console.log(process.env.NODE_ENV);

Then defineprocess.env.NODE_ENV in vite.config.ts:

return defineConfig({
  define: {
    'process.env.NODE_ENV': JSON.stringify('development'),
  }
});

Then I execute the following command for development

npx vite --mode dev --force

It turned out that after the vite compilation, it became

console.log('dev'); // why??????

So I repeatedly made debug and found that, vite was forcibly replaced with process.env.NODE_ENV with vite mode option

Position to code: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/clientInjections.ts#L56-L59

It can be seen that vite is directly replaced by process.env.NODE_ENV in the code to mode option


I hope not to link the mode option and process.env.NODE_ENV

The two of them are two different things, let alone the code of the direct replace user

Reproduction

https://stackblitz.com/edit/vitejs-vite-qfdg3v?file=main.js,package-lock.json&terminal=dev

System Info

System:
    OS: macOS 12.3.1
    CPU: (16) x64 Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
    Memory: 8.61 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.3 - ~/.nvm/versions/node/v14.18.3/bin/node
    npm: 6.14.15 - ~/.nvm/versions/node/v14.18.3/bin/npm
  Browsers:
    Chrome: 101.0.4951.64
    Safari: 15.4
    Safari Technology Preview: 15.4

Used Package Manager

npm

Logs

No response

Validations

@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant