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 Answers
Reset to default 17The 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.
<script type="module">
is required – CodingIntrigue Commented Sep 29, 2017 at 8:25<script type="module">
I got this error:Uncaught TypeError: Failed to resolve module specifier 'Mymodule'
@CodingIntrigue – Arvin Commented Sep 29, 2017 at 8:35