Closed jcbhmr closed 1 year ago
Yeah, it's this:
??=
is invalid 2020 syntax, so it goes to the catch {}
block and ignores it; thus leading to there being no exports, and thus leading to a syntax error.
To fix this, I think that all you'd need to do is change 2020 to "latest" or 2023
Here is the diff that solved my problem:
diff --git a/node_modules/vite-plugin-commonjs/dist/index.js b/node_modules/vite-plugin-commonjs/dist/index.js
index 9e8973b..73ebd5e 100644
--- a/node_modules/vite-plugin-commonjs/dist/index.js
+++ b/node_modules/vite-plugin-commonjs/dist/index.js
@@ -390,7 +390,7 @@ async function transformCommonjs({
return;
let ast;
try {
- ast = acorn.parse(code, { sourceType: "module", ecmaVersion: 2020 });
+ ast = acorn.parse(code, { sourceType: "module", ecmaVersion: "latest" });
} catch (error) {
return null;
}
diff --git a/node_modules/vite-plugin-commonjs/dist/index.mjs b/node_modules/vite-plugin-commonjs/dist/index.mjs
index faaa42a..586d5d0 100644
--- a/node_modules/vite-plugin-commonjs/dist/index.mjs
+++ b/node_modules/vite-plugin-commonjs/dist/index.mjs
@@ -388,7 +388,7 @@ async function transformCommonjs({
return;
let ast;
try {
- ast = parse(code, { sourceType: "module", ecmaVersion: 2020 });
+ ast = parse(code, { sourceType: "module", ecmaVersion: "latest" });
} catch (error) {
return null;
}
This issue body was partially generated by patch-package.
acron@7.x
allowed latest ecamVersion
is 11
or 2020
see here, current vite-plugin-commonjs not force use the acron@8.x
.
Maybe ecmaVersion: 14
is better, because acron source code use the >
operate for compare rather than ===
What's the reference to acorn@7? 🤔 It looks like you use acorn@8 which should work with "latest" right? https://github.com/vite-plugin/vite-plugin-commonjs/blob/647fe26351c7b3a662afd7fc29569f068877cc3f/package.json#L29
vs
I assume that something about this package breaks when using
??=
syntax?