You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome v61中ES6 import报Unexpected identifier错误求助

Fixing the Unexpected identifier Error with ES6 import in Chrome v61

Hey there! I totally get why this is confusing—you’ve got ES6 working fine in your ex.js file, but as soon as you add an import statement, Chrome throws that frustrating Unexpected identifier error. Let’s walk through the most likely fixes step by step:

1. You’re not loading your script as an ES module

Chrome v61 does support ES6 modules, but only if you tell the browser to treat your script as one. By default, <script> tags load files in "classic script" mode, which doesn’t recognize import/export syntax at all.

Fix:

Update your script tag in HTML to include the type="module" attribute:

<script type="module" src="./js/ex.js"></script>

This tells Chrome to parse the file as an ES module, where import/export are valid syntax. Also, keep in mind that modules run in strict mode automatically, so you don’t need to add 'use strict' manually.

2. Double-check your import path

A tiny typo in your path can easily trigger this error. Chrome is strict about file paths, especially when running locally:

  • Make sure the path in your import matches the actual file location exactly (case-sensitive! audiohandler.js ≠ AudioHandler.js)
  • Use full relative paths: import AudioHandler from './js/AudioHandler.js' (don’t omit the ./ or the .js extension—modules require explicit extensions in most cases)
  • Verify that AudioHandler.js actually exists in the ./js/ directory, and that it’s exporting something correctly (e.g., export default class AudioHandler { ... })

3. Local file:// protocol limitations

If you’re opening your HTML file directly from your computer (using the file:// URL), Chrome blocks certain module behaviors due to cross-origin security restrictions. The error message might be misleading, but the root issue is the browser’s security rules for local files.

Fix:

Run your code on a local web server instead. Here are quick ways to do this:

  • If you have Python 3 installed: Open your project folder in terminal and run python -m http.server
  • If you have Node.js installed: Run npx serve in your project folder
    Then access your page via http://localhost:8000 (or the port your server uses) instead of opening the file directly.

4. Verify Chrome’s module support (just to be sure)

While Chrome 61 should have ES module support enabled by default, it’s worth a quick check:

  • Type chrome://flags/#enable-javascript-harmony into your address bar
  • Make sure the "Experimental JavaScript" flag is set to "Enabled" (though this is default in 61)

Quick recap of steps to try:

  1. Add type="module" to your script tag
  2. Validate your import path and confirm the target file exists
  3. Switch to a local web server instead of using the file:// protocol

That should get your import statement working properly in Chrome v61!

内容的提问来源于stack exchange,提问作者Kornelia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:52:35