Skip to content

Commit 7c27e17

Browse files
Fix ERR_PACKAGE_PATH_NOT_EXPORTED error on loading option-t.
This error happens by this change in [Node,js v13.10](nodejs/node#31625) and I think we can regard this problem as the regression of this library. For the future, we should wait nodejs/node#32107 but it is still in progress. This patch will try to workaround for it. * nodejs/node#31625 * nodejs/node#32107 * babel/babel#11216
1 parent d824a11 commit 7c27e17

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "22.2.2",
44
"description": "Option type implementation whose APIs are inspired by Rust's `Option<T>`.",
55
"type": "commonjs",
6-
"main": "cjs/index.js",
6+
"main": "./cjs/index.js",
77
"files": [
88
"CHANGELOG.md",
99
"cjs/",

tools/package_json_rewriter/transformer/add_exports_field/main.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
'use strict';
22

3-
const { loadHistoricalPathInfo, addHistoricalPathToExportsFields } = require('./compatibility');
3+
const assert = require('assert');
4+
5+
const {
6+
loadHistoricalPathInfo,
7+
addHistoricalPathToExportsFields,
8+
} = require('./compatibility');
49

510
const BASE_DIR = __dirname;
611

12+
function addMainFieldFromPackageJSON(targetObject, manifestInfo) {
13+
const mainPath = manifestInfo.main;
14+
assert.strictEqual(typeof mainPath, 'string', `package.json's 'main' field is not string`);
15+
assert.ok(mainPath.startsWith('./'), `package.json's 'main' field should start with ./`);
16+
17+
// eslint-disable-next-line no-param-reassign
18+
targetObject['.'] = mainPath;
19+
}
20+
721
async function addExportsFields(json) {
822
const o = Object.create(null);
923

1024
const histricalJSPathList = await loadHistoricalPathInfo(BASE_DIR, '../../../pkg_files.json');
1125
addHistoricalPathToExportsFields(o, histricalJSPathList);
1226

27+
// For the future, we may have a chance to remove this
28+
// when https://github.com/nodejs/node/issues/32107/ has been fixed.
29+
addMainFieldFromPackageJSON(o, json);
30+
1331
// eslint-disable-next-line no-param-reassign
1432
json.exports = o;
1533
}

0 commit comments

Comments
 (0)