import 声明


import 语句可以引用 ES 模块或 CommonJS 模块。

当导入 CommonJS 模块 时,提供 module.exports 对象作为默认导出。 命名导出可能可用,由静态分析提供,以方便更好的生态系统兼容性。

import { sin, cos } from 'geometry/trigonometry-functions.mjs';

An import statement can reference an ES module or a CommonJS module. import statements are permitted only in ES modules. For similar functionality in CommonJS, see import().

When importing CommonJS modules, the module.exports object is provided as the default export. Named exports may be available, provided by static analysis as a convenience for better ecosystem compatibility.

Additional experimental flags are available for importing Wasm modules or JSON modules. For importing native modules or JSON modules unflagged, see module.createRequire().

The specifier of an import statement (the string after the from keyword) can either be an URL-style relative path like './file.mjs' or a package name like 'fs'.

Like in CommonJS, files within packages can be accessed by appending a path to the package name; unless the package’s package.json contains an "exports" field, in which case files within packages need to be accessed via the path defined in "exports".

import { sin, cos } from 'geometry/trigonometry-functions.mjs';