Skip to content

False positive of ?inline check for styles.css.ts file #11328

@manucorporat

Description

@manucorporat

Describe the bug

Typescript and node-resolution allows to import files dropping the last extension so a file named styles.css.ts can be imported like:

import {export1, export2} from './styles.css';

Leading to a false positive of this warning:

Default and named imports from CSS files are deprecated. Use the ?inline query instead. For example: import { counter } from './styles.css?inline'

The new import analysys in vite 4 is detecting usage of named exports in side-effect imports of .css files, but in order to do so, it's checking the AST values instead of the resolved Id to the file

https://github.com/BuilderIO/vite/blob/dcc0004ceb7a76e6d0cbae8b84a103a15f80049b/packages/vite/src/node/plugins/importAnalysis.ts#L441-L447

This is problematic since it's a false positive of importing some non-css files like the described example

Reproduction

https://stackblitz.com/edit/vitejs-vite-bedqvf?file=file.css.js,main.js&terminal=dev

Steps to reproduce

See warnings in the console:

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vite: ^4.0.0 => 4.0.0

Used Package Manager

pnpm

Logs

No response

Validations

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