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

process.env.NODE_ENV in package.json is incorrectly replaced #4173

Closed
ambar opened this issue Jul 8, 2021 · 3 comments · Fixed by #7294
Closed

process.env.NODE_ENV in package.json is incorrectly replaced #4173

ambar opened this issue Jul 8, 2021 · 3 comments · Fixed by #7294

Comments

@ambar
Copy link

ambar commented Jul 8, 2021

Describe the bug

import {version} from '../package.json'

Reproduction

{
  "name": "mylib",
  "version": "0.0.0",
  "scripts": {
    "dev": "microbundle --define process.env.NODE_ENV='production'"
  }
}

System Info

System:
    OS: macOS 11.2.3
    CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
    Memory: 231.29 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.14.10 - ~/.nvm/versions/node/v12.20.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 91.0.4472.114
    Chrome Canary: 93.0.4568.0
    Firefox: 88.0.1
    Safari: 14.0.3
    Safari Technology Preview: 14.2


### Used Package Manager

yarn

### Logs

```shell
SyntaxError: Unexpected token (4:17)
    at Object.pp$4.raise (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:41641:13)
    at Object.pp.unexpected (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:39149:8)
    at Object.pp.expect (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:39143:26)
    at Object.pp$3.parseObj (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:41255:12)
    at Object.pp$3.parseExprAtom (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:40994:17)
    at Object.pp$3.parseExprSubscripts (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:40813:19)
    at Object.pp$3.parseMaybeUnary (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:40779:17)
    at Object.parseMaybeUnary (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:49616:29)
    at Object.pp$3.parseExprOps (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:40712:19)
    at Object.pp$3.parseMaybeConditional (node_modules/vite/dist/node/chunks/dep-fc2895ac.js:40695:19)


### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/.github/contributing.md).
- [X] Read the [docs](https://vitejs.dev/guide).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] 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.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
@ghost
Copy link

ghost commented Jul 8, 2021

Try this

{
  "name": "mylib",
  "version": "0.0.0",
  "scripts": {
    "dev": "microbundle --define NODE_ENV=production"
  }
}

or this
https://vitejs.dev/guide/env-and-mode.html#modes

@ambar
Copy link
Author

ambar commented Jul 9, 2021

@web2033 That's inconvenient for testing env.

@bluwy
Copy link
Member

bluwy commented Mar 12, 2022

This should be fixed since #5515. But leaving it open since there's an optimization opportunity to skip define for JSON files.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 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.

3 participants