You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/guide/troubleshooting.md
+17
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,23 @@ You will need to either:
15
15
- Switch to another package manager (e.g. `pnpm`, `yarn`)
16
16
- Remove `&` from the path to your project
17
17
18
+
## Config
19
+
20
+
### This package is ESM only
21
+
22
+
When importing a ESM only package by `require`, the following error happens.
23
+
24
+
> Failed to resolve "foo". This package is ESM only but it was tried to load by `require`.
25
+
26
+
> "foo" resolved to an ESM file. ESM file cannot be loaded by `require`.
27
+
28
+
ESM files cannot be loaded by [`require`](<https://nodejs.org/docs/latest-v18.x/api/esm.html#require:~:text=Using%20require%20to%20load%20an%20ES%20module%20is%20not%20supported%20because%20ES%20modules%20have%20asynchronous%20execution.%20Instead%2C%20use%20import()%20to%20load%20an%20ES%20module%20from%20a%20CommonJS%20module.>).
29
+
30
+
We recommend converting your config to ESM by either:
31
+
32
+
- adding `"type": "module"` to the nearest `package.json`
33
+
- renaming `vite.config.js`/`vite.config.ts` to `vite.config.mjs`/`vite.config.mts`
)}. This package is ESM only but it was tried to load by \`require\`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`,
1079
+
)
1080
+
}
1081
+
}
1082
+
throwe
1083
+
}
1084
+
if(idFsPath&&isImport){
1047
1085
idFsPath=pathToFileURL(idFsPath).href
1048
1086
}
1087
+
if(idFsPath&&!isImport&&isESMFile(idFsPath)){
1088
+
thrownewError(
1089
+
`${JSON.stringify(
1090
+
id,
1091
+
)} resolved to an ESM file. ESM file cannot be loaded by \`require\`. See http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`,
0 commit comments