Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active December 19, 2021 14:19
Show Gist options
  • Save rauschma/0c3590c21ad585908d59cf6549321dbc to your computer and use it in GitHub Desktop.
Save rauschma/0c3590c21ad585908d59cf6549321dbc to your computer and use it in GitHub Desktop.

ECMAScript module specifiers

There are three kinds of module specifiers:

  • Absolute specifiers are full URLs that are used directly – for example:

    'file:///opt/nodejs/config.mjs'
    'https://unpkg.com/liltest@0.0.5/dist/liltest.js'
    
  • Relative specifiers are relative URLs that are resolved against the URL of the importing module – for example:

    // URL of importing module
    const u = 'https://example.com/public/dir/a.js';
    assert.equal(
      new URL('./b.js', u).toString(),
      'https://example.com/public/dir/b.js'
    );
    assert.equal(
      new URL('../c.mjs', u).toString(),
      'https://example.com/public/c.mjs'
    );
    assert.equal(
      new URL('../../tmp/d.js', u).toString(),
      'https://example.com/tmp/d.js'
    );
  • Bare specifiers are paths (without protocol and domain) that start with neither slashes nor dots – for example:

    'some-package'
    'lodash/fp/add'
    

Source: https://nodejs.org/api/esm.html#terminology

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment