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

import.meta.env parse error when present in string for production build #14835

Closed
7 tasks done
jasong-au opened this issue Oct 31, 2023 · 1 comment
Closed
7 tasks done

Comments

@jasong-au
Copy link

Describe the bug

As a simple test writing my first pinia store I wanted to log to the console the values of some settings we store in the env files.
This worked fine in dev mode, but when doing a build I got an error:

[vite:build-import-analysis] Parse error @:1:1
file: C:/git/test-app/src/stores/test.ts
error during build:
Error: Parse error @:1:1
    at parse$e (file:///C:/git/test-app/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:16497:355)
    at Object.transform (file:///C:/git/test-app/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:46642:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
ERROR: "build-only" exited with 1.

This didn't have a lot of information (just the file name) and was difficult to track down, but it came down to lines like this:

console.log('import.meta.env.VITE_DATA_API_URL', import.meta.env.VITE_DATA_API_URL)

The problem is the first parameter, the string. If I replace the first period with a space, it builds. According to the docs, it should replace the values even inside strings which I didn't think about, but instead it gives me this parse error and no line number to look at. In dev mode the value is not replaced inside the string so it works fine.

Reproduction

https://github.com/jasong-au/test-app-error

Steps to reproduce

Create new app, add a variable to .env, attempt to include the import in a single quoted string.

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 7.12 GB / 31.85 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.4.0 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Chrome: 118.0.5993.118
    Edge: Spartan (44.19041.1266.0), Chromium (118.0.2088.76)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @vitejs/plugin-vue: ^4.2.3 => 4.4.0
    vite: ^4.4.5 => 4.5.0

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Nov 1, 2023

Fixed in #11151

@bluwy bluwy closed this as completed Nov 1, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants