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

CSS default import warning appears for pre-bundled dependencies even if the import is unused #12304

Closed
7 tasks done
caghand opened this issue Mar 6, 2023 · 4 comments · Fixed by #12343
Closed
7 tasks done
Labels
feat: css feat: deps optimizer Esbuild Dependencies Optimization p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@caghand
Copy link

caghand commented Mar 6, 2023

Describe the bug

#11094 added a warning for importing the default export of a CSS file.
Then, #11121 disabled this warning when the default import of a CSS file is not used.
However, the warning still exists for pre-bundled dependencies where the default import is not used.

Reproduction

https://stackblitz.com/edit/vitejs-vite-juhqxl?file=main.js

Steps to reproduce

Look at this line in the vott-ct package: https://github.com/microsoft/CanvasTools-for-VOTT/blob/master/src/canvastools/ts/ct.ts#L86
The transpiled code in the npm package looks like this:
require("./../css/canvastools.css");
Then, the dependency pre-bundling step (optimizeDeps) translates it to the following block:

// vite:dep-pre-bundle:external-conversion:D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css
var canvastools_exports = {};
__export(canvastools_exports, {
  default: () => default2
});
import { default as default2 } from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css";
import * as canvastools_star from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css";
var init_canvastools = __esm({
  "vite:dep-pre-bundle:external-conversion:D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css"() {
    init_esbuildNodeGlobals();
    __reExport(canvastools_exports, canvastools_star);
  }
});

Then, when importing from vott-ct, we see the following warnings in dev mode:

9:28:35 PM [vite] warning:
D:/<path_to_project>/node_modules/.vite/deps/vott-ct.js
5462|    default: () => default2
5463|  });
5464|  import { default as default2 } from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css";
   |                                       ^
5465|  import * as canvastools_star from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css";
5466|  var init_canvastools = __esm({
Default and named imports from CSS files are deprecated. Use the ?inline query instead. For example: import { default as default2 } from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css?inline"
  Plugin: vite:import-analysis
  File: D:/<path_to_project>/node_modules/.vite/deps/vott-ct.js?v=09e38d5f
9:28:35 PM [vite] warning:
D:/<path_to_project>/node_modules/.vite/deps/vott-ct.js
5463|  });
5464|  import { default as default2 } from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css";
5465|  import * as canvastools_star from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css";
   |                                     ^
5466|  var init_canvastools = __esm({
5467|    "vite:dep-pre-bundle:external-conversion:D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css"() {
Default and named imports from CSS files are deprecated. Use the ?inline query instead. For example: import * as canvastools_star from "D:/<path_to_project>/node_modules/vott-ct/lib/css/canvastools.css?inline"
  Plugin: vite:import-analysis
  File: D:/<path_to_project>/node_modules/.vite/deps/vott-ct.js?v=09e38d5f

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz
    Memory: 32.63 GB / 63.95 GB
  Binaries:
    Node: 14.20.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.21.1 - D:\<path_to_project>\node_modules\.bin\yarn.CMD
    npm: 6.14.17 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (110.0.1587.57)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.0.1 => 1.0.1
    @vitejs/plugin-react: ^3.1.0 => 3.1.0
    vite: ^4.1.4 => 4.1.4

Used Package Manager

yarn

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Mar 6, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Mar 6, 2023
@sun0day
Copy link
Member

sun0day commented Mar 7, 2023

I think this works as expected cause canvastools_star is used to reexport even though import VottTest from 'vott-ct'; hasn't been used.

In the meantime, directly importing unused default CSS shouldn't show this warning. @sapphi-red

@caghand
Copy link
Author

caghand commented Mar 8, 2023

Yes, I understand that the warning is shown because of canvastools_star.
But, to be precise, this issue is unrelated to whether import VottTest from 'vott-ct'; is used or not.
Rather, it's about this: If the dependency has something like require("./../css/canvastools.css");, then the pre-bundled (optimized) version (with canvastools_star) should not produce the warning. Maybe by optimizing the code in a different way (without canvastools_star), or maybe by suppressing the warning somehow..?

@caghand
Copy link
Author

caghand commented Mar 12, 2023

Thanks a lot, @sun0day and @sapphi-red!

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: css feat: deps optimizer Esbuild Dependencies Optimization p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants