目标必须是相对 URL
【Targets must be relative URLs】
"exports" 地图中的所有目标路径(与导出键相关的值)必须是以 ./ 开头的相对 URL 字符串。
【All target paths in the "exports" map (the values associated with export
keys) must be relative URL strings starting with ./.】
// package.json
{
"name": "my-package",
"exports": {
".": "./dist/main.js", // Correct
"./feature": "./lib/feature.js", // Correct
// "./origin-relative": "/dist/main.js", // Incorrect: Must start with ./
// "./absolute": "file:///dev/null", // Incorrect: Must start with ./
// "./outside": "../common/util.js" // Incorrect: Must start with ./
}
} 此行为的原因包括:
【Reasons for this behavior include:】
- 安全性: 防止从包自身目录之外导出任意文件。
- 封装: 确保所有导出的路径都相对于包根进行解析,使包成为自包含的。