You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the define plugin to create a global __DEV__ var. A dependency of the project (see reproduction) includes the following code: var __DEV__ = process.env.NODE_ENV !== 'production';. Vite replaces the __DEV__ part with false during the build process. The resulting code is var false = process.env.NODE_ENV !== 'production';, which isn't valid js.
I would expect the define plugin not to touch any code outside the src/ directory, e.g. node_modules (yarn v1) or .yarn/cache (yarn v2).
Full explanation (see reproduction):
The define plugin allows the use of a global var called __DEV__. Take a look at the src/App.tsx file (line 11) to see it in action. The define plugin statically replaces this part of the code with a boolean during the build process, e.g. if (__DEV__) becomes if (false). However, the warning dependency is also defining a var named __DEV__. Vite replaces this part as well. The final code in warning.js looks something like this: var false = process.env.NODE_ENV !== "production". That's not valid js, the build fails.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
Describe the bug
I'm using the define plugin to create a global
__DEV__
var. A dependency of the project (see reproduction) includes the following code:var __DEV__ = process.env.NODE_ENV !== 'production';
. Vite replaces the__DEV__
part withfalse
during the build process. The resulting code isvar false = process.env.NODE_ENV !== 'production';
, which isn't valid js.I would expect the define plugin not to touch any code outside the
src/
directory, e.g.node_modules
(yarn v1) or.yarn/cache
(yarn v2).Full explanation (see reproduction):
The define plugin allows the use of a global var called
__DEV__
. Take a look at thesrc/App.tsx
file (line 11) to see it in action. The define plugin statically replaces this part of the code with a boolean during the build process, e.g.if (__DEV__)
becomesif (false)
. However, thewarning
dependency is also defining a var named__DEV__
. Vite replaces this part as well. The final code in warning.js looks something like this:var false = process.env.NODE_ENV !== "production"
. That's not valid js, the build fails.Reproduction
Repo: https://github.com/unzico/vite-define-failing-build
git clone
andcd
yarn
yarn build
-> failsyarn build
-> doesn't failSystem Info
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: