-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Uncaught SyntaxError: Unexpected token 'export' #7130
Comments
|
I tried putting the library in the
|
for whoever want vite to produce a umd build use this in your import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
build: {
target: "es2015",
lib: {
entry: "src/main.tsx",
formats: ["umd"],
name: "App",
},
},
}); Then you could import functions and vars from this file by accessing "App.*" |
Interesting. This looks like a bug to me. |
I was not able to reproduce this in my environment. $ tree -I node_modules -L 4
.
├── index.html
├── package-lock.json
├── package.json
└── public
└── src
└── lib
└── pyodide
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "2.8.6"
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script src="/src/lib/pyodide/pyodide.js"></script>
<script>
async function main(){
let pyodide = await loadPyodide({
indexURL: "/src/lib/pyodide",
});
console.log(pyodide.runPython("1 + 2"));
}
main();
</script>
</head>
<body>
<div id="app"></div>
</body>
</html> Also when I put it in src folder a different error occured. (I think this error is correct.)
|
I will make a repo to show the bug tomorrow |
@Weiyi-Feng Did you able to create a reproduction? |
Hello @Weiyi-Feng. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
This issue was solved by updating vite to 2.9.2 |
This issue sounds related to #8037 |
My The solution was to rename the the relevant file with a System info
|
if you developing in older browser make sure your transpile target is compatible. import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
esbuild:{
target:"es2018"
}
}); |
Describe the bug
If we use vite worked with some 3rd library like pyodide, they will get an error like
Uncaught SyntaxError: Unexpected token 'export'
.Reproduction
Download pyodide full version from the release page and extract it to src/lib/pyodide.
Error:
Uncaught SyntaxError: Unexpected token 'export'
And we can see the
/src/lib/pyodide/pyodide.js
content in chrome devtool, it's converted to the following content:but in fact, we only want the original content of it, so is there has a way to let users get the original js content?
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: