es6 导入和导出中的模块说明符
module specifier in es6 import and export
我对这些语句中的模块说明符指的是什么感到困惑:
export {bar} from "foo";
import {bar} from "foo";
"foo"
指的是什么?它不能是文件,因为它类似于 "./foo"
。如果它不是一个文件,我认为它是一个 ID。 ID是怎么定义的?
我正在从 js 文件导出,但导入将成为 firefox 浏览器中内联 html 脚本 (type="module"
) 的一部分。
已验证浏览器版本(和浏览器设置)可与 es6 模块一起使用。
提前致谢。
ES6 没有指定模块说明符指的是什么。
它确实只是:一个标识符。仅此而已。
由环境将这些标识符解析为实际模块。加载程序可能会将它们解释为相对文件路径、全局 ID、npm 模块名称以及其他任何内容。
在浏览器中,<script type="module">
took some time to specify, but it's here finally. A module specifier of "foo"
is currently invalid, a browser will ignore that module as it doesn't know what to do with it. It will need something that resolves to an URL to load. Jake Archibald wrapped it up succinctly:
"Bare" import specifiers aren't currently supported. Valid module
specifiers must match one of the following:
- A full non-relative URL. As in, it doesn't throw an error when put
through
new URL(moduleSpecifier)
.
- Starts with
/
.
- Starts with
./
.
- Starts with
../
.
Other specifiers are reserved for future-use, such as importing built-in
modules.
我对这些语句中的模块说明符指的是什么感到困惑:
export {bar} from "foo";
import {bar} from "foo";
"foo"
指的是什么?它不能是文件,因为它类似于 "./foo"
。如果它不是一个文件,我认为它是一个 ID。 ID是怎么定义的?
我正在从 js 文件导出,但导入将成为 firefox 浏览器中内联 html 脚本 (type="module"
) 的一部分。
已验证浏览器版本(和浏览器设置)可与 es6 模块一起使用。
提前致谢。
ES6 没有指定模块说明符指的是什么。
它确实只是:一个标识符。仅此而已。
由环境将这些标识符解析为实际模块。加载程序可能会将它们解释为相对文件路径、全局 ID、npm 模块名称以及其他任何内容。
在浏览器中,<script type="module">
took some time to specify, but it's here finally. A module specifier of "foo"
is currently invalid, a browser will ignore that module as it doesn't know what to do with it. It will need something that resolves to an URL to load. Jake Archibald wrapped it up succinctly:
"Bare" import specifiers aren't currently supported. Valid module specifiers must match one of the following:
- A full non-relative URL. As in, it doesn't throw an error when put through
new URL(moduleSpecifier)
.- Starts with
/
.- Starts with
./
.- Starts with
../
.Other specifiers are reserved for future-use, such as importing built-in modules.