Module specifier in es6 imports and exports

I'm confused as to what the module specifier in these expressions refers to:

export {bar} from "foo";

import {bar} from "foo";

      

What does it mean "foo"

? It cannot be a file, as it would be something like "./foo"

. If it is not a file, I will assume it is an ID. How is the identifier determined?

I am exporting from a js file, but the import will be part of the inline html script ( type="module"

) in Firefox browser.

Browser version (and browser settings) checked to work with es6 modules.

Thanks in advance.

+3


source to share


1 answer


ES6 does not specify what a module specifier refers to.
It really is: an identifier. Nothing more.

It remains for the environment to resolve these identifiers in the real module. The loader can interpret them as relative file paths, as global identifiers, as npm module names, or anything else.



It <script type="module">

took a while
in browsers to point out , but it's here finally. The module specifier "foo"

is currently invalid, the browser ignores this module as it doesn't know what to do with it. This will require something that allows URL loading. Jake Archibald squeezed it succinctly :

"Bare" import specifications are not currently supported. Valid module specifiers must match one of the following:

  • Full non-relative URL. As in the case, it does not 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.

+4


source







All Articles