Uncaught SyntaxError: Unexpected token 'export'
See original GitHub issueDescribe 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.
<script src="/src/lib/pyodide/pyodide.js"></script>
<script type="text/javascript">
async function main(){
let pyodide = await loadPyodide({
indexURL: "/src/lib/pyodide",
});
console.log(pyodide.runPython("1 + 2"));
}
main();
</script>
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:
export default "/src/lib/pyodide/pyodide.js"
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
System:
OS: Windows 10 10.0.19042
CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
Memory: 1.27 GB / 7.81 GB
Binaries:
Node: 17.0.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (98.0.1108.62)
Internet Explorer: 11.0.19041.1202
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Getting Unexpected Token Export - javascript - Stack Overflow
The problem was that I was changing my code from non-modules to modules and I forgot to delete the imported script file. My...
Read more >SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >How to Fix „Uncaught SyntaxError: Unexpected token 'export
Using type="module" on the <script> tag solved the „Unexpected token export ” error. The browser runs the imported JavaScript without issues.
Read more >How to Solve Unexpected Token 'export' Error in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >SyntaxError: Unexpected token 'export' - Abhishek Kumar
In case you are getting error like 'Unexpected token export' while starting the server, then export like below in schema.js
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
pyodide.js
is a UMD file. Vite only works with ESM if you put it undersrc
. The only way to get UMD to work is either prebundle it, or put it inpublic
and link to the script in html. And I think the latter solution would work for this case.This issue was solved by updating vite to 2.9.2