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

Using import.meta.url in vite.config.ts shows error in IDE (VS Code) #6311

Closed
7 tasks done
NMinhNguyen opened this issue Dec 29, 2021 · 1 comment · Fixed by #6324
Closed
7 tasks done

Using import.meta.url in vite.config.ts shows error in IDE (VS Code) #6311

NMinhNguyen opened this issue Dec 29, 2021 · 1 comment · Fixed by #6324
Labels
p1-chore Doesn't change code behavior (priority) pending triage

Comments

@NMinhNguyen
Copy link
Contributor

Describe the bug

If you create a brand new Vite app and add console.log(import.meta.url) to vite.config.ts, you'll see an error in VS Code:

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node12', or 'nodenext'. ts(1343)

Adding vite.config.ts to tsconfig.json's include array solves the issue but I wonder if there's any downsides to doing this by default. One I can think of is that vite.config.ts can rely on Node.js stuff but tsconfig.json is primarily for the browser environment if I'm not mistaken.

// tsconfig.json
  "include": ["./src", "./vite.config.ts"]

Bear in mind that StackBlitz won't show you this, you'll need to download the project and open it locally.

Reproduction

https://stackblitz.com/edit/vitejs-vite-yv42yg?file=vite.config.ts

System Info

System:
    OS: Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: Unknown - /bin/jsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @vitejs/plugin-react: ^1.0.7 => 1.1.3 
    vite: ^2.7.2 => 2.7.9

Used Package Manager

yarn

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Dec 30, 2021

There shouldn't be any downsides to that. I think it should be fine to add the config into the starter templates. Feel free to make a PR.

@bluwy bluwy added the p1-chore Doesn't change code behavior (priority) label Dec 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p1-chore Doesn't change code behavior (priority) pending triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants