Skip to content

Commit eaff76a

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. ## Reference * nodejs/node#31625 * nodejs/node#32107 * babel/babel#11216
1 parent d824a11 commit eaff76a

File tree

1 file changed

+19
-1
lines changed
  • tools/package_json_rewriter/transformer/add_exports_field

1 file changed

+19
-1
lines changed

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)