Skip to content

Commit 2b80243

Browse files
authored
refactor!: bump required node version to 20.19+, 22.12+ and remove cjs build (#20032)
1 parent 61b6b96 commit 2b80243

File tree

19 files changed

+55
-258
lines changed

19 files changed

+55
-258
lines changed

docs/guide/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The supported template presets are:
4444
## Scaffolding Your First Vite Project
4545

4646
::: tip Compatibility Note
47-
Vite requires [Node.js](https://nodejs.org/en/) version 20+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
47+
Vite requires [Node.js](https://nodejs.org/en/) version 20.19+, 22.12+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
4848
:::
4949

5050
::: code-group

docs/guide/troubleshooting.md

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,6 @@ See [Rollup's troubleshooting guide](https://rollupjs.org/troubleshooting/) for
44

55
If the suggestions here don't work, please try posting questions on [GitHub Discussions](https://github.com/vitejs/vite/discussions) or in the `#help` channel of [Vite Land Discord](https://chat.vite.dev).
66

7-
## CJS
8-
9-
### Vite CJS Node API deprecated
10-
11-
The CJS build of Vite's Node API is deprecated and will be removed in Vite 6. See the [GitHub discussion](https://github.com/vitejs/vite/discussions/13928) for more context. You should update your files or frameworks to import the ESM build of Vite instead.
12-
13-
In a basic Vite project, make sure:
14-
15-
1. The `vite.config.js` file content is using the ESM syntax.
16-
2. The closest `package.json` file has `"type": "module"`, or use the `.mjs`/`.mts` extension, e.g. `vite.config.mjs` or `vite.config.mts`.
17-
18-
For other projects, there are a few general approaches:
19-
20-
- **Configure ESM as default, opt-in to CJS if needed:** Add `"type": "module"` in the project `package.json`. All `*.js` files are now interpreted as ESM and need to use the ESM syntax. You can rename a file with the `.cjs` extension to keep using CJS instead.
21-
- **Keep CJS as default, opt-in to ESM if needed:** If the project `package.json` does not have `"type": "module"`, all `*.js` files are interpreted as CJS. You can rename a file with the `.mjs` extension to use ESM instead.
22-
- **Dynamically import Vite:** If you need to keep using CJS, you can dynamically import Vite using `import('vite')` instead. This requires your code to be written in an `async` context, but should still be manageable as Vite's API is mostly asynchronous.
23-
24-
If you're unsure where the warning is coming from, you can run your script with the `VITE_CJS_TRACE=true` flag to log the stack trace:
25-
26-
```bash
27-
VITE_CJS_TRACE=true vite dev
28-
```
29-
30-
If you'd like to temporarily ignore the warning, you can run your script with the `VITE_CJS_IGNORE_WARNING=true` flag:
31-
32-
```bash
33-
VITE_CJS_IGNORE_WARNING=true vite dev
34-
```
35-
36-
Note that postcss config files do not support ESM + TypeScript (`.mts` or `.ts` in `"type": "module"`) yet. If you have postcss configs with `.ts` and added `"type": "module"` to package.json, you'll also need to rename the postcss config to use `.cts`.
37-
387
## CLI
398

409
### `Error: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js'`
@@ -245,3 +214,18 @@ An example of cross drive links are:
245214
- a symlink/junction to a different drive by `mklink` command (e.g. Yarn global cache)
246215

247216
Related issue: [#10802](https://github.com/vitejs/vite/issues/10802)
217+
218+
<script setup lang="ts">
219+
// redirect old links with hash to old version docs
220+
if (typeof window !== "undefined") {
221+
const hashForOldVersion = {
222+
'vite-cjs-node-api-deprecated': 6
223+
}
224+
225+
const version = hashForOldVersion[location.hash.slice(1)]
226+
if (version) {
227+
// update the scheme and the port as well so that it works in local preview (it is http and 4173 locally)
228+
location.href = `https://v${version}.vite.dev` + location.pathname + location.search + location.hash
229+
}
230+
}
231+
</script>

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default tseslint.config(
5252
},
5353
settings: {
5454
node: {
55-
version: '^20.0.0 || >=22.0.0',
55+
version: '^20.19.0 || >=22.12.0',
5656
},
5757
},
5858
plugins: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"type": "module",
55
"engines": {
6-
"node": "^20.0.0 || >=22.0.0"
6+
"node": "^20.19.0 || >=22.12.0"
77
},
88
"homepage": "https://vite.dev/",
99
"repository": {

packages/create-vite/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Scaffolding Your First Vite Project
44

55
> **Compatibility Note:**
6-
> Vite requires [Node.js](https://nodejs.org/en/) version 20+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
6+
> Vite requires [Node.js](https://nodejs.org/en/) version 20.19+, 22.12+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
77
88
With NPM:
99

packages/create-vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"prepublishOnly": "npm run build"
2121
},
2222
"engines": {
23-
"node": "^20.0.0 || >=22.0.0"
23+
"node": "^20.19.0 || >=22.12.0"
2424
},
2525
"repository": {
2626
"type": "git",

packages/plugin-legacy/package.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,14 @@
1313
"vite-plugin",
1414
"@vitejs/plugin-legacy"
1515
],
16-
"main": "./dist/index.cjs",
17-
"module": "./dist/index.js",
18-
"types": "./dist/index.d.ts",
19-
"exports": {
20-
".": {
21-
"import": "./dist/index.js",
22-
"require": "./dist/index.cjs"
23-
}
24-
},
16+
"exports": "./dist/index.js",
2517
"scripts": {
2618
"dev": "tsdown --watch",
27-
"build": "tsdown && pnpm run patch-cjs",
28-
"patch-cjs": "tsx ../../scripts/patchCJS.ts",
19+
"build": "tsdown",
2920
"prepublishOnly": "npm run build"
3021
},
3122
"engines": {
32-
"node": "^20.0.0 || >=22.0.0"
23+
"node": "^20.19.0 || >=22.12.0"
3324
},
3425
"repository": {
3526
"type": "git",

packages/plugin-legacy/src/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -987,22 +987,25 @@ function wrapIIFEBabelPlugin(): BabelPlugin {
987987
}
988988
}
989989

990-
const hash =
991-
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- crypto.hash is supported in Node 21.7.0+, 20.12.0+
992-
crypto.hash ??
993-
((
994-
algorithm: string,
995-
data: crypto.BinaryLike,
996-
outputEncoding: crypto.BinaryToTextEncoding,
997-
) => crypto.createHash(algorithm).update(data).digest(outputEncoding))
998-
999990
export const cspHashes = [
1000991
safari10NoModuleFix,
1001992
systemJSInlineCode,
1002993
detectModernBrowserCode,
1003994
dynamicFallbackInlineCode,
1004-
].map((i) => hash('sha256', i, 'base64'))
995+
].map((i) => crypto.hash('sha256', i, 'base64'))
1005996

1006997
export type { Options }
1007998

1008999
export default viteLegacyPlugin
1000+
1001+
// Compat for require
1002+
function viteLegacyPluginCjs(this: unknown, options: Options): Plugin[] {
1003+
return viteLegacyPlugin.call(this, options)
1004+
}
1005+
Object.assign(viteLegacyPluginCjs, {
1006+
cspHashes,
1007+
default: viteLegacyPluginCjs,
1008+
detectPolyfills,
1009+
})
1010+
1011+
export { viteLegacyPluginCjs as 'module.exports' }

packages/plugin-legacy/tsdown.config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import { defineConfig } from 'tsdown'
22

33
export default defineConfig({
44
entry: ['src/index.ts'],
5-
format: ['esm', 'cjs'],
65
target: 'node20',
76
tsconfig: false, // disable tsconfig `paths` when bundling
8-
outputOptions(opts, format) {
9-
if (format === 'cjs') {
10-
opts.exports = 'named'
11-
}
12-
return opts
13-
},
7+
dts: true,
148
})

packages/vite/index.cjs

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy