When the target of tsconfig.json is es5, how to use es6 in the configuration file? #3827
-
I created a But When I changed the target of So how to change the target only when building the project with This may related to evanw/esbuild#1355 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
Would be helpful if you share your |
Beta Was this translation helpful? Give feedback.
-
If anyone finds themselves here I was able to work around this issue with patch-package diff --git a/node_modules/vite/dist/node/chunks/dep-1513d487.js b/node_modules/vite/dist/node/chunks/dep-1513d487.js
index 4b12ad1..4db815a 100644
--- a/node_modules/vite/dist/node/chunks/dep-1513d487.js
+++ b/node_modules/vite/dist/node/chunks/dep-1513d487.js
@@ -38849,7 +38849,7 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
function defineImport(node, source) {
deps.add(source);
const importId = `__vite_ssr_import_${uid++}__`;
- s.appendLeft(node.start, `const ${importId} = await ${ssrImportKey}(${JSON.stringify(source)});\n`);
+ s.appendLeft(node.start, `var ${importId} = await ${ssrImportKey}(${JSON.stringify(source)});\n`);
return importId;
}
function defineExport(position, name, local = name) {
@@ -38975,7 +38975,7 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
declaredConst.add(id.name);
// locate the top-most node containing the class declaration
const topNode = parentStack[parentStack.length - 2];
- s.prependRight(topNode.start, `const ${id.name} = ${binding};\n`);
+ s.prependRight(topNode.start, `var ${id.name} = ${binding};\n`);
}
}
else {
@@ -40535,13 +40535,13 @@ function transformCjsImport(importExp, url, rawUrl, importIndex) {
const lines = [`import ${cjsModuleName} from "${url}"`];
importNames.forEach(({ importedName, localName }) => {
if (importedName === '*') {
- lines.push(`const ${localName} = ${cjsModuleName}`);
+ lines.push(`var ${localName} = ${cjsModuleName}`);
}
else if (importedName === 'default') {
- lines.push(`const ${localName} = ${cjsModuleName}.__esModule ? ${cjsModuleName}.default : ${cjsModuleName}`);
+ lines.push(`var ${localName} = ${cjsModuleName}.__esModule ? ${cjsModuleName}.default : ${cjsModuleName}`);
}
else {
- lines.push(`const ${localName} = ${cjsModuleName}["${importedName}"]`);
+ lines.push(`var ${localName} = ${cjsModuleName}["${importedName}"]`);
}
});
if (defaultExports) {
@@ -40632,7 +40632,7 @@ function buildImportAnalysisPlugin(config) {
const assetsURL = relativePreloadUrls
? `function(dep,importerUrl) { return new URL(dep, importerUrl).href }`
: `function(dep) { return ${JSON.stringify(config.base)}+dep }`;
- const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
+ const preloadCode = `var scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
return {
name: 'vite:build-import-analysis',
resolveId(id) {
@@ -40776,7 +40776,7 @@ function buildImportAnalysisPlugin(config) {
}
if (needPreloadHelper &&
insertPreload &&
- !source.includes(`const ${preloadMethod} =`)) {
+ !source.includes(`var ${preloadMethod} =`)) {
str().prepend(`import { ${preloadMethod} } from "${preloadHelperId}";`);
}
if (s) {
@@ -40946,7 +40946,7 @@ function modulePreloadPolyfillPlugin(config) {
}
if (!polyfillString) {
polyfillString =
- `const p = ${polyfill.toString()};` + `${isModernFlag}&&p();`;
+ `var p = ${polyfill.toString()};` + `${isModernFlag}&&p();`;
}
return polyfillString;
}
@@ -41862,8 +41862,8 @@ function cssPostPlugin(config) {
const devBase = config.base;
return [
`import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify(path$n.posix.join(devBase, CLIENT_PUBLIC_PATH))}`,
- `const __vite__id = ${JSON.stringify(id)}`,
- `const __vite__css = ${JSON.stringify(cssContent)}`,
+ `var __vite__id = ${JSON.stringify(id)}`,
+ `var __vite__css = ${JSON.stringify(cssContent)}`,
`__vite__updateStyle(__vite__id, __vite__css)`,
// css modules exports change on edit so it can't self accept
`${modulesCode ||
@@ -59941,7 +59941,7 @@ function webWorkerPlugin(config) {
const chunk = await bundleWorkerEntry(config, id, query);
// inline as blob data url
return {
- code: `const encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
+ code: `var encodedJs = "${Buffer.from(chunk.code).toString('base64')}";
const blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
export default function WorkerWrapper() {
const objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
@@ -62773,9 +62773,9 @@ async function bundleConfigFile(fileName, isESM) {
setup(build) {
build.onLoad({ filter: /\.[cm]?[jt]s$/ }, async (args) => {
const contents = await fs$l.promises.readFile(args.path, 'utf8');
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path$n.dirname(args.path))};` +
- `const ${filenameVarName} = ${JSON.stringify(args.path)};` +
- `const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(args.path).href)};`;
+ const injectValues = `var ${dirnameVarName} = ${JSON.stringify(path$n.dirname(args.path))};` +
+ `var ${filenameVarName} = ${JSON.stringify(args.path)};` +
+ `var ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(args.path).href)};`;
return {
loader: args.path.endsWith('ts') ? 'ts' : 'js',
contents: injectValues + contents |
Beta Was this translation helpful? Give feedback.
-
#9457 will fix this error. |
Beta Was this translation helpful? Give feedback.
#9457 will fix this error.