术语


import 语句的说明符是 from 关键字之后的字符串,例如 import { sep } from 'path' 中的 'path'。 说明符也用于 export from 语句,并作为 import() 表达式的参数。

  • 相对说明符,如 './startup.js''../config.mjs'。 它们指的是相对于导入文件位置的路径。

  • 绝对说明符,如 'file:///opt/nodejs/config.js'。 它们直接且明确地引用完整的路径。

The specifier of an import statement is the string after the from keyword, e.g. 'path' in import { sep } from 'path'. Specifiers are also used in export from statements, and as the argument to an import() expression.

There are four types of specifiers:

  • Bare specifiers like 'some-package'. They refer to an entry point of a package by the package name.

  • Deep import specifiers like 'some-package/lib/shuffle.mjs'. They refer to a path within a package prefixed by the package name.

  • Relative specifiers like './startup.js' or '../config.mjs'. They refer to a path relative to the location of the importing file.

  • Absolute specifiers like 'file:///opt/nodejs/config.js'. They refer directly and explicitly to a full path.

Bare specifiers, and the bare specifier portion of deep import specifiers, are strings; but everything else in a specifier is a URL.

file:, node:, and data: URLs are supported. A specifier like 'https://example.com/app.js' may be supported by browsers but it is not supported in Node.js.

Specifiers may not begin with / or //. These are reserved for potential future use. The root of the current volume may be referenced via file:///.