ESModule
ESModule only
目前有些库采取了esmodule only的处理方式,可以从package.json中看到:
Node.js 默认将 JavaScript 代码视为 CommonJS 模块。 作者可以通过 .mjs 文件扩展名、package.json “type” 字段、或 —input-type 标志告诉 Node.js 将 JavaScript 代码视为 ECMAScript 模块。 有关更多详细信息,请参阅包模块。
node >= 23,type 设置为 module,以及拥有 exports 作为导出
{"name": "escape-goat","version": "4.0.0","description": "Escape a string for use in HTML or the inverse","license": "MIT","repository": "sindresorhus/escape-goat","author": {"name": "Sindre Sorhus","email": "sindresorhus@gmail.com","url": "https://sindresorhus.com"},"type": "module","exports": "./index.js","engines": {"node": ">=12"},"scripts": {"test": "xo && ava && tsd"},"files": ["index.js","index.d.ts"],}
exports 说明:https://medium.com/swlh/npm-new-package-json-exports-field-1a7d1f489ccf
exports 官方文档:https://nodejs.org/api/packages.html#packages_exports
