Slide 40
Slide 40 text
Node.js v12.11.0での実行例
{
"name": "example-package",
"main": "./libs/main",
"exports": {
"bun": "./libs/main.ts",
"require": "./libs/main.js",
"default": "./libs/main.mjs"
}
}
package.json $ node --experimental-modules example.mjs
(node:30008) ExperimentalWarning: The ESM module loader is experimental.
internal/modules/esm/default_resolve.js:79
let url = moduleWrapResolve(specifier, parentURL);
^
Error: Cannot resolve package exports target 'undefined' matched for '.' in
/PATH/TO/example/node_modules/example-package/package.json, imported from
/PATH/TO/example/example.mjs
at Loader.resolve [as _resolve]
(internal/modules/esm/default_resolve.js:79:13)
at Loader.resolve (internal/modules/esm/loader.js:73:33)
at Loader.getModuleJob (internal/modules/esm/loader.js:152:40)
at ModuleWrap. (internal/modules/esm/module_job.js:43:40)
at link (internal/modules/esm/module_job.js:42:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
import example from "example-package"; example.mjs
"exports"の中に "." が
ないよ!