Skip to content

[2.4.0-beta.2] import.meta.env does not typecheck on linux #4028

@IanVS

Description

@IanVS

Describe the bug

#4003 moved the definition of ImportMeta to a separate file and added a triple-slash directive to reference it. This works fine on case-insensitive operating systems, but not on linux. This seems to be because typescript converts the path to a lowercase string, vite/types/importmeta. This is not resolved on linux, and expressions like import.meta.env will throw a typescript error.

On mac, when I run npx tsc --traceResolution I get:

======== Type reference directive 'vite/types/importmeta' was successfully resolved to '/<absprojectpath>/node_modules/vite/types/importmeta.d.ts' with Package ID 'vite/types/[email protected]', primary: false. ========

On Linux, my coworker sees:

======== Type reference directive 'vite/types/importmeta' was not resolved. ========

I think this is probably a typescript bug, but as a workaround I think it should be possible to rename the files to all-lowercase.

Reproduction

I'm not really sure how to show a reproduction of this problem...

System Info

Works on:


System:
    OS: macOS 11.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 352.24 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.1/bin/yarn
    npm: 7.19.0 - ~/.nvm/versions/node/v14.16.1/bin/npm
  Browsers:
    Brave Browser: 91.1.26.67
    Firefox: 88.0.1
    Safari: 14.1.1
  npmPackages:
    vite: ^2.4.0-beta.2 => 2.4.0-beta.2

I don't have a linux box to run the command on.



### Used Package Manager

npm

### Logs

_No response_

### 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/).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions