Skip to content

Unexpected string when using globalThis.process.env.NODE_ENV #12185

Closed
@vojtechsimetka

Description

Describe the bug

Running vite dev substitutes globalThis.process.env.NODE_ENV into globalThis."development". This causes console error SyntaxError: Unexpected string. This kind of code is usually in some dependency and can not be easily replaced.

It looks like this is a known problem but I have not found any issue reported here nor in documentation how it can be solved. Here is one potential "workaround" https://github.com/DougAnderson444/ipfs-vite-svelte-kit#processenvnode_env-in-svelte-dev

Reproduction

https://stackblitz.com/edit/vitejs-vite-kfsmj6?file=counter.js

Steps to reproduce

Just use globalThis.process.env.NODE_ENV somewhere in code and run vite dev

System Info

System:
    OS: macOS 13.2.1
    CPU: (8) arm64 Apple M1
    Memory: 184.16 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v16.14.2/bin/yarn
    npm: 8.19.4 - ~/.../node_modules/.bin/npm
  Browsers:
    Brave Browser: 110.1.48.164
    Chrome: 110.0.5481.177
    Safari: 16.3

Used Package Manager

npm

Logs

Screenshot 2023-02-24 at 12 02 42

Validations

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions