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

Initializing Vite in a folder with a .env file breaks vite command #4761

Closed
7 tasks done
timohermans opened this issue Aug 27, 2021 · 3 comments
Closed
7 tasks done

Comments

@timohermans
Copy link

timohermans commented Aug 27, 2021

Describe the bug

When I'm trying to run npm run dev on a vite project that is initialized in a folder with a .env file, breaks.

First I thought it was my Django project, but after stripping everything from the repo except the .env file, I know for certain this breaks it. The error:

error when starting dev server:
RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at interpolate (path/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75367:28)
    at path/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75385:17
    at Array.reduce (<anonymous>)
    at interpolate (path/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75369:20)
    at path/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75385:17
    at Array.reduce (<anonymous>)
    at interpolate (path/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75369:20)
    at path/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75385:17
    at Array.reduce (<anonymous>)

Reproduction

https://github.com/timohermans/vite-env-bug

repro steps

git clone git@github.com:timohermans/vite-env-bug.git
cd frontend
npm install
npm run dev

System Info

System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 127.80 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.11 - /usr/local/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
  Browsers:
    Chrome: 92.0.4515.159
    Edge: 92.0.902.84
    Firefox: 90.0.2
    Safari: 14.1.2
  npmPackages:
    vite: ^2.5.1 => 2.5.1

Used Package Manager

npm

Logs

➜  frontend npm run dev -- --debug

> frontend@0.0.0 dev /Users/timohermans/projects/personal/repro/frontend
> vite "--debug"

  vite:config no config file found. +0ms
[dotenv][DEBUG] did not match key and value when parsing line 7: 
error when starting dev server:
RangeError: Maximum call stack size exceeded
    at String.match (<anonymous>)
    at interpolate (/Users/timohermans/projects/personal/repro/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75367:28)
    at /Users/timohermans/projects/personal/repro/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75385:17
    at Array.reduce (<anonymous>)
    at interpolate (/Users/timohermans/projects/personal/repro/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75369:20)
    at /Users/timohermans/projects/personal/repro/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75385:17
    at Array.reduce (<anonymous>)
    at interpolate (/Users/timohermans/projects/personal/repro/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75369:20)
    at /Users/timohermans/projects/personal/repro/frontend/node_modules/vite/dist/node/chunks/dep-972722fa.js:75385:17
    at Array.reduce (<anonymous>)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.0.0 dev: `vite "--debug"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the frontend@0.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/timohermans/.npm/_logs/2021-08-27T07_24_02_244Z-debug.log

Validations

@timohermans timohermans changed the title Initializing Vite a folder with a .env file breaks Vite command Initializing Vite in a folder with a .env file breaks Vite command Aug 27, 2021
@timohermans timohermans changed the title Initializing Vite in a folder with a .env file breaks Vite command Initializing Vite in a folder with a .env file breaks vite command Aug 27, 2021
@timohermans
Copy link
Author

Temporary fix: create an empty .env file in the frontend folder

@ghost
Copy link

ghost commented Aug 27, 2021

Can reproduce on win10 too.

@bluwy
Copy link
Member

bluwy commented Mar 18, 2022

This is fixed since #6995 as only .env files in the frontend project is loaded. Parent directories won't be looked for. Though from the stack trace alone, it seems to be an issue with self-referential variables on this line where dotenv-expand doesn't handle that motdotla/dotenv-expand#67. You may need to workaround this if this is used in the frontend

@bluwy bluwy closed this as completed Mar 18, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 2, 2022
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