Ask any question about JavaScript here... and get an instant response.
Why am I getting "Uncaught SyntaxError: Unexpected token export" when trying to use ES6 modules in my browser?
Asked on Oct 25, 2025
Answer
The "Uncaught SyntaxError: Unexpected token export" error occurs when you try to use ES6 modules in a browser that does not support them, or when you haven't set up your environment correctly to recognize module syntax. Ensure your HTML file uses the "type" attribute set to "module" in the script tag.
<!-- BEGIN COPY / PASTE -->
<script type="module">
// Example of using ES6 module syntax
export function greet() {
console.log("Hello, world!");
}
</script>
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with JavaScript best practices.- Make sure your browser supports ES6 modules. Most modern browsers do, but older versions may not.
- Use the "type" attribute set to "module" in your script tag to enable ES6 module syntax.
- Ensure your server is correctly serving your JavaScript files if you are using a server setup.
- If using a local file system, consider using a local server as some browsers restrict module loading from local files.
Recommended Links:
