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

Vite 5: The CJS build of Vite's Node API is deprecated #1236

Closed
2 tasks done
gkiely opened this issue Nov 16, 2023 · 6 comments · Fixed by #1262
Closed
2 tasks done

Vite 5: The CJS build of Vite's Node API is deprecated #1236

gkiely opened this issue Nov 16, 2023 · 6 comments · Fixed by #1262
Assignees
Labels
priority-low Low priority issue upstream issue Issue caused by a required upstream dependency

Comments

@gkiely
Copy link

gkiely commented Nov 16, 2023

Describe the bug

Vanilla extract appears to be using CJS which vite no longer supports

Reproduction

https://codesandbox.io/p/sandbox/eloquent-bird-9dl86m

System Info

System:
    OS: macOS 12.7
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.35 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.2.0 - ~/.volta/tools/image/node/20.2.0/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 9.6.6 - ~/.volta/tools/image/node/20.2.0/bin/npm
    bun: 1.0.11 - ~/.bun/bin/bun
    Watchman: 2023.04.10.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 114.1.52.129
    Chrome: 119.0.6045.159
    Edge: 119.0.2151.58
    Safari: 17.0
  npmPackages:
    @vanilla-extract/vite-plugin: ^3.9.1 => 3.9.1 
    vite: ^5.0.0 => 5.0.0

Used Package Manager

npm

Logs

Trace: The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
    at warnCjsUsage (/Users/grantkiely/code/example/node_modules/vite/index.cjs:32:3)
    at Object.<anonymous> (/Users/grantkiely/code/example/node_modules/vite/index.cjs:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at Object.<anonymous> (/Users/grantkiely/code/example/node_modules/@vanilla-extract/vite-plugin/dist/vanilla-extract-vite-plugin.cjs.dev.js:6:12)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)

Validations

@mrm007 mrm007 self-assigned this Nov 16, 2023
@askoufis
Copy link
Contributor

The CJS API is still supported, it's just deprecated. There's no rush to fix it, but we might as well do it sooner rather than later.

@mrm007 mrm007 added upstream issue Issue caused by a required upstream dependency priority-low Low priority issue and removed pending triage labels Nov 16, 2023
@markdalgleish
Copy link
Contributor

Can we do a dynamic import of Vite in the async config plugin hook and then store the result in a variable? That's how we dealt with this in the Remix Vite plugin.

@jxom
Copy link

jxom commented Nov 30, 2023

Alternative could be for the ESM output to have .mjs extension instead of .esm.js, as Vite seems to treat all .js files as CJS if package.json#type is not "module".

@NovaAstra
Copy link

For me, who is a console freak, this is unacceptable.😊

@arturmuller
Copy link

For me, who is a console freak, this is unacceptable.😊

For anyone who is bothered by the — rather dramatic — warning that Vite prints to the console, you can squash it by setting the VITE_CJS_IGNORE_WARNING env var to true as explained in Vite's troubleshooting docs.

@mrm007
Copy link
Contributor

mrm007 commented Dec 28, 2023

The issue wasn't just lazy loading vite, which we already do in some places:

const vite = await import('vite');

But Preconstruct converts that to a Promise.resolve().then(() => require('vite') (as seen here).

This should be fixed in #1262.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-low Low priority issue upstream issue Issue caused by a required upstream dependency
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants