-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Global constant defined by config.define should not replace variable name #5269
Copy link
Copy link
Closed
Labels
Description
Describe the bug
When config Vite:
{
define: {
__DEV__: JSON.stringify(process.env.NODE_ENV === 'development')
}
}Cause the following code replacement problems
https://github.com/BerkeleyTrue/warning/blob/122d08acff1b42ed421aa027c1f5fabe207f38d5/warning.js#L17
var __DEV__ = process.env.NODE_ENV !== 'production';This line of code will be replaced with var false = false that Cause js to run an SyntaxError: Unexpected keyword 'false'.
Reproduction
When config Vite:
{
define: {
__DEV__: JSON.stringify(process.env.NODE_ENV === 'development')
}
}System Info
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Memory: 1.65 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.18.0 - ~/.nvm/versions/node/v14.18.0/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.14.15 - ~/.nvm/versions/node/v14.18.0/bin/npm
Browsers:
Edge: 93.0.961.38
Firefox: 87.0
Safari: 15.0
npmPackages:
@vitejs/plugin-vue: ^1.9.3 => 1.9.3
vite: ^2.6.7 => 2.6.5Used Package Manager
yarn
Logs
17: var __DEV__ = process.env.NODE_ENV !== 'production';
error during build:
SyntaxError: Unexpected keyword 'false' (15:4) in /Users/jony/projects/vue3-proj/node_modules/warning/warning.js
at Parser.pp$5.raise (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:19495:13)
at Parser.pp$4.checkUnreserved (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:19395:12)
at Parser.pp$4.parseIdent (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:19431:10)
at Parser.pp$2.parseBindingAtom (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:18057:15)
at Parser.pp$1.parseVarId (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:17378:18)
at Parser.pp$1.parseVar (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:17361:10)
at Parser.pp$1.parseVarStatement (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:17227:8)
at Parser.pp$1.parseStatement (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16975:17)
at Parser.pp$1.parseTopLevel (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16877:21)
at Parser.parse (/Users/jony/projects/vue3-proj/node_modules/vite/node_modules/rollup/dist/shared/rollup.js:16658:15)
error Command failed with exit code 1.Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- 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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable