最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - import can't be used in chrome 61? - Stack Overflow

programmeradmin7浏览0评论

I'm trying to play ES6 features in the latest release version of chrome, that is chrome 61, and I met the error during using the import key word. Technically, import is used as following method but the console showed me errors:

import Mymodule from "Mymodule.js"

the console printed:

Uncaught SyntaxError: Unexpected identifier

I have already turn the following experimental features on:

chrome://flags/#enable-javascript-harmony
chrome://flags/#enable-module-scripts

and following off:

chrome://flags/#disable-javascript-harmony-shipping

I'm trying to play ES6 features in the latest release version of chrome, that is chrome 61, and I met the error during using the import key word. Technically, import is used as following method but the console showed me errors:

import Mymodule from "Mymodule.js"

the console printed:

Uncaught SyntaxError: Unexpected identifier

I have already turn the following experimental features on:

chrome://flags/#enable-javascript-harmony
chrome://flags/#enable-module-scripts

and following off:

chrome://flags/#disable-javascript-harmony-shipping
Share Improve this question edited Sep 29, 2017 at 8:25 Andreas 21.9k7 gold badges51 silver badges58 bronze badges asked Sep 29, 2017 at 8:23 ArvinArvin 1422 silver badges7 bronze badges 5
  • 2 How are you including the script? <script type="module"> is required – CodingIntrigue Commented Sep 29, 2017 at 8:25
  • 1 html.spec.whatwg.org/multipage/… – Andreas Commented Sep 29, 2017 at 8:30
  • 1 After adding <script type="module"> I got this error: Uncaught TypeError: Failed to resolve module specifier 'Mymodule' @CodingIntrigue – Arvin Commented Sep 29, 2017 at 8:35
  • I tried messing around with this too, noticed import is a valid keyword in the console but couldn't get it to work – neaumusic Commented Oct 2, 2017 at 19:19
  • matthewphillips.info/posts/loading-app-with-script-module – ᄂ ᄀ Commented Nov 23, 2017 at 13:20
Add a comment  | 

2 Answers 2

Reset to default 17

The problem is that from "Mymodule.js".

A module must be either a full URL (including a protocol), an absolute path (starting with /), or a relative path (starting with ./ or ../).

Any other strings are reserved for future use.

source: https://jakearchibald.com/2017/es-modules-in-browsers/#bare-import-specifiers-arent-currently-supported (referenced from https://developers.google.com/web/updates/2017/09/nic61#modules )

"import" support is not yet natively included in Chrome, but is currently in development

https://www.chromestatus.com/feature/5684934484164608

Until then you would need to compile and bundle your code with something like Babel and Browserify or Webpack.

Update: As mentioned below by @neaumusic, this feature is part of Chrome 61. The What's New note references Paul Irish's Module-implementation as an example.

It would help to see your MyModule.js code, to see exactly what it is your module is exporting. This partially determines how you phrase your 'import' statements.

发布评论

评论列表(0)

  1. 暂无评论