Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d065334

Browse filesBrowse files
guybedfordcodebytere
authored andcommitted
module: package "imports" field
PR-URL: #34117 Backport-PR-URL: #35385 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
1 parent b7be751 commit d065334
Copy full SHA for d065334

File tree

Expand file treeCollapse file tree

16 files changed

+537
-175
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

16 files changed

+537
-175
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,12 @@ A non-context-aware native addon was loaded in a process that disallows them.
16831683

16841684
A given value is out of the accepted range.
16851685

1686+
<a id="ERR_PACKAGE_IMPORT_NOT_DEFINED"></a>
1687+
### `ERR_PACKAGE_IMPORT_NOT_DEFINED`
1688+
1689+
The `package.json` ["imports" field][] does not define the given internal
1690+
package specifier mapping.
1691+
16861692
<a id="ERR_PACKAGE_PATH_NOT_EXPORTED"></a>
16871693
### `ERR_PACKAGE_PATH_NOT_EXPORTED`
16881694

@@ -2533,3 +2539,4 @@ closed.
25332539
[vm]: vm.html
25342540
[self-reference a package using its name]: esm.html#esm_self_referencing_a_package_using_its_name
25352541
[define a custom subpath]: esm.html#esm_subpath_exports
2542+
["imports" field]: esm.html#esm_internal_package_imports
Collapse file

‎doc/api/esm.md‎

Copy file name to clipboardExpand all lines: doc/api/esm.md
+122-37Lines changed: 122 additions & 37 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,43 @@ and in a CommonJS one. For example, this code will also work:
546546
const { something } = require('a-package/foo'); // Loads from ./foo.js.
547547
```
548548

549+
### Internal package imports
550+
551+
In addition to the `"exports"` field it is possible to define internal package
552+
import maps that only apply to import specifiers from within the package itself.
553+
554+
Entries in the imports field must always start with `#` to ensure they are
555+
clearly disambiguated from package specifiers.
556+
557+
For example, the imports field can be used to gain the benefits of conditional
558+
exports for internal modules:
559+
560+
```json
561+
// package.json
562+
{
563+
"imports": {
564+
"#dep": {
565+
"node": "dep-node-native",
566+
"default": "./dep-polyfill.js"
567+
}
568+
},
569+
"dependencies": {
570+
"dep-node-native": "^1.0.0"
571+
}
572+
}
573+
```
574+
575+
where `import '#dep'` would now get the resolution of the external package
576+
`dep-node-native` (including its exports in turn), and instead get the local
577+
file `./dep-polyfill.js` relative to the package in other environments.
578+
579+
Unlike the exports field, import maps permit mapping to external packages
580+
because this provides an important use case for conditional loading and also can
581+
be done without the risk of cycles, unlike for exports.
582+
583+
Apart from the above, the resolution rules for the imports field are otherwise
584+
analogous to the exports field.
585+
549586
### Dual CommonJS/ES module packages
550587

551588
Prior to the introduction of support for ES modules in Node.js, it was a common
@@ -1577,10 +1614,11 @@ The resolver can throw the following errors:
15771614
or package subpath specifier.
15781615
* _Invalid Package Configuration_: package.json configuration is invalid or
15791616
contains an invalid configuration.
1580-
* _Invalid Package Target_: Package exports define a target module within the
1581-
package that is an invalid type or string target.
1617+
* _Invalid Package Target_: Package exports or imports define a target module
1618+
for the package that is an invalid type or string target.
15821619
* _Package Path Not Exported_: Package exports do not define or permit a target
15831620
subpath in the package for the given module.
1621+
* _Package Import Not Defined_: Package imports do not define the specifier.
15841622
* _Module Not Found_: The package or module requested does not exist.
15851623

15861624
<details>
@@ -1592,11 +1630,14 @@ The resolver can throw the following errors:
15921630
> 1. If _specifier_ is a valid URL, then
15931631
> 1. Set _resolvedURL_ to the result of parsing and reserializing
15941632
> _specifier_ as a URL.
1595-
> 1. Otherwise, if _specifier_ starts with _"/"_, then
1596-
> 1. Throw an _Invalid Module Specifier_ error.
1597-
> 1. Otherwise, if _specifier_ starts with _"./"_ or _"../"_, then
1633+
> 1. Otherwise, if _specifier_ starts with _"/"_, _"./"_ or _"../"_, then
15981634
> 1. Set _resolvedURL_ to the URL resolution of _specifier_ relative to
15991635
> _parentURL_.
1636+
> 1. Otherwise, if _specifier_ starts with _"#"_, then
1637+
> 1. Set _resolvedURL_ to the result of
1638+
> **PACKAGE_INTERNAL_RESOLVE**(_specifier_, _parentURL_).
1639+
> 1. If _resolvedURL_ is **null** or **undefined**, throw a
1640+
> _Package Import Not Defined_ error.
16001641
> 1. Otherwise,
16011642
> 1. Note: _specifier_ is now a bare specifier.
16021643
> 1. Set _resolvedURL_ the result of
@@ -1634,7 +1675,7 @@ The resolver can throw the following errors:
16341675
> 1. If _packageSubpath_ contains any _"."_ or _".."_ segments or percent
16351676
> encoded strings for _"/"_ or _"\\"_, then
16361677
> 1. Throw an _Invalid Module Specifier_ error.
1637-
> 1. Set _selfUrl_ to the result of
1678+
> 1. Let _selfUrl_ be the result of
16381679
> **SELF_REFERENCE_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
16391680
> 1. If _selfUrl_ isn't empty, return _selfUrl_.
16401681
> 1. If _packageSubpath_ is _undefined_ and _packageName_ is a Node.js builtin
@@ -1657,8 +1698,11 @@ The resolver can throw the following errors:
16571698
> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then
16581699
> 1. Let _exports_ be _pjson.exports_.
16591700
> 1. If _exports_ is not **null** or **undefined**, then
1660-
> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_,
1661-
> _packageSubpath_, _pjson.exports_).
1701+
> 1. Let _resolved_ be the result of **PACKAGE_EXPORTS_RESOLVE**(
1702+
> _packageURL_, _packageSubpath_, _pjson.exports_).
1703+
> 1. If _resolved_ is **null** or **undefined**, throw a
1704+
> _Package Path Not Exported_ error.
1705+
> 1. Return _resolved_.
16621706
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
16631707
> 1. Throw a _Module Not Found_ error.
16641708
@@ -1679,8 +1723,11 @@ The resolver can throw the following errors:
16791723
> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then
16801724
> 1. Let _exports_ be _pjson.exports_.
16811725
> 1. If _exports_ is not **null** or **undefined**, then
1682-
> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_,
1683-
> _pjson.exports_).
1726+
> 1. Let _resolved_ be the result of **PACKAGE_EXPORTS_RESOLVE**(
1727+
> _packageURL_, _subpath_, _pjson.exports_).
1728+
> 1. If _resolved_ is **null** or **undefined**, throw a
1729+
> _Package Path Not Exported_ error.
1730+
> 1. Return _resolved_.
16841731
> 1. Return the URL resolution of _subpath_ in _packageURL_.
16851732
> 1. Otherwise, return **undefined**.
16861733
@@ -1693,12 +1740,18 @@ The resolver can throw the following errors:
16931740
> not starting with _"."_, throw an _Invalid Package Configuration_ error.
16941741
> 1. If _pjson.exports_ is a String or Array, or an Object containing no
16951742
> keys starting with _"."_, then
1696-
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
1697-
> _pjson.exports_, _""_).
1743+
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1744+
> _packageURL_, _pjson.exports_, _""_, **false**, _defaultEnv_).
1745+
> 1. If _resolved_ is **null** or **undefined**, throw a
1746+
> _Package Path Not Exported_ error.
1747+
> 1. Return _resolved_.
16981748
> 1. If _pjson.exports_ is an Object containing a _"."_ property, then
16991749
> 1. Let _mainExport_ be the _"."_ property in _pjson.exports_.
1700-
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
1701-
> _mainExport_, _""_).
1750+
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1751+
> _packageURL_, _mainExport_, _""_, **false**, _defaultEnv_).
1752+
> 1. If _resolved_ is **null** or **undefined**, throw a
1753+
> _Package Path Not Exported_ error.
1754+
> 1. Return _resolved_.
17021755
> 1. Throw a _Package Path Not Exported_ error.
17031756
> 1. Let _legacyMainURL_ be the result applying the legacy
17041757
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
@@ -1712,31 +1765,37 @@ The resolver can throw the following errors:
17121765
> 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
17131766
> 1. If _packagePath_ is a key of _exports_, then
17141767
> 1. Let _target_ be the value of _exports\[packagePath\]_.
1715-
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_,
1716-
> _""_, _defaultEnv_).
1768+
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
1769+
> _""_, **false**, _defaultEnv_).
17171770
> 1. Let _directoryKeys_ be the list of keys of _exports_ ending in
17181771
> _"/"_, sorted by length descending.
17191772
> 1. For each key _directory_ in _directoryKeys_, do
17201773
> 1. If _packagePath_ starts with _directory_, then
17211774
> 1. Let _target_ be the value of _exports\[directory\]_.
17221775
> 1. Let _subpath_ be the substring of _target_ starting at the index
17231776
> of the length of _directory_.
1724-
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_,
1725-
> _subpath_, _defaultEnv_).
1726-
> 1. Throw a _Package Path Not Exported_ error.
1777+
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
1778+
> _subpath_, **false**, _defaultEnv_).
1779+
> 1. Return **null**.
17271780
1728-
**PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _env_)
1781+
**PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _internal_, _env_)
17291782
17301783
> 1. If _target_ is a String, then
1731-
> 1. If _target_ does not start with _"./"_ or contains any _"node_modules"_
1732-
> segments including _"node_modules"_ percent-encoding, throw an
1733-
> _Invalid Package Target_ error.
1784+
> 1. If _target_ contains any _"node_modules"_ segments including
1785+
> _"node_modules"_ percent-encoding, throw an _Invalid Package Target_
1786+
> error.
1787+
> 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
1788+
> throw an _Invalid Module Specifier_ error.
1789+
> 1. If _target_ does not start with _"./"_, then
1790+
> 1. If _target_ does not start with _"../"_ or _"/"_ and is not a valid
1791+
> URL, then
1792+
> 1. If _internal_ is **true**, return **PACKAGE_RESOLVE**(
1793+
> _target_ + _subpath_, _packageURL_ + _"/"_)_.
1794+
> 1. Otherwise throw an _Invalid Package Target_ error.
17341795
> 1. Let _resolvedTarget_ be the URL resolution of the concatenation of
17351796
> _packageURL_ and _target_.
17361797
> 1. If _resolvedTarget_ is not contained in _packageURL_, throw an
17371798
> _Invalid Package Target_ error.
1738-
> 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
1739-
> throw an _Invalid Module Specifier_ error.
17401799
> 1. Let _resolved_ be the URL resolution of the concatenation of
17411800
> _subpath_ and _resolvedTarget_.
17421801
> 1. If _resolved_ is not contained in _resolvedTarget_, throw an
@@ -1748,22 +1807,48 @@ The resolver can throw the following errors:
17481807
> 1. For each property _p_ of _target_, in object insertion order as,
17491808
> 1. If _p_ equals _"default"_ or _env_ contains an entry for _p_, then
17501809
> 1. Let _targetValue_ be the value of the _p_ property in _target_.
1751-
> 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(
1752-
> _packageURL_, _targetValue_, _subpath_, _env_), continuing the
1753-
> loop on any _Package Path Not Exported_ error.
1754-
> 1. Throw a _Package Path Not Exported_ error.
1810+
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1811+
> _packageURL_, _targetValue_, _subpath_, _internal_, _env_)
1812+
> 1. If _resolved_ is equal to **undefined**, continue the loop.
1813+
> 1. Return _resolved_.
1814+
> 1. Return **undefined**.
17551815
> 1. Otherwise, if _target_ is an Array, then
1756-
> 1. If _target.length is zero, throw a _Package Path Not Exported_ error.
1816+
> 1. If _target.length is zero, return **null**.
17571817
> 1. For each item _targetValue_ in _target_, do
1758-
> 1. If _targetValue_ is an Array, continue the loop.
1759-
> 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
1760-
> _targetValue_, _subpath_, _env_), continuing the loop on any
1761-
> _Package Path Not Exported_ or _Invalid Package Target_ error.
1762-
> 1. Throw the last fallback resolution error.
1763-
> 1. Otherwise, if _target_ is _null_, throw a _Package Path Not Exported_
1764-
> error.
1818+
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1819+
> _packageURL_, _targetValue_, _subpath_, _internal_, _env_),
1820+
> continuing the loop on any _Invalid Package Target_ error.
1821+
> 1. If _resolved_ is **undefined**, continue the loop.
1822+
> 1. Return _resolved_.
1823+
> 1. Return or throw the last fallback resolution **null** return or error.
1824+
> 1. Otherwise, if _target_ is _null_, return **null**.
17651825
> 1. Otherwise throw an _Invalid Package Target_ error.
17661826
1827+
**PACKAGE_INTERNAL_RESOLVE**(_specifier_, _parentURL_)
1828+
1829+
> 1. Assert: _specifier_ begins with _"#"_.
1830+
> 1. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
1831+
> 1. Throw an _Invalid Module Specifier_ error.
1832+
> 1. Let _packageURL_ be the result of **READ_PACKAGE_SCOPE**(_parentURL_).
1833+
> 1. If _packageURL_ is not **null**, then
1834+
> 1. Let _pjson_ be the result of **READ_PACKAGE_JSON**(_packageURL_).
1835+
> 1. If _pjson.imports is a non-null Object, then
1836+
> 1. Let _imports_ be _pjson.imports_.
1837+
> 1. If _specifier_ is a key of _imports_, then
1838+
> 1. Let _target_ be the value of _imports\[specifier\]_.
1839+
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
1840+
> _""_, **true**, _defaultEnv_).
1841+
> 1. Let _directoryKeys_ be the list of keys of _imports_ ending in
1842+
> _"/"_, sorted by length descending.
1843+
> 1. For each key _directory_ in _directoryKeys_, do
1844+
> 1. If _specifier_ starts with _directory_, then
1845+
> 1. Let _target_ be the value of _imports\[directory\]_.
1846+
> 1. Let _subpath_ be the substring of _target_ starting at the
1847+
> index of the length of _directory_.
1848+
> 1. Return **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
1849+
> _subpath_, **true**, _defaultEnv_).
1850+
> 1. Return **null**.
1851+
17671852
**ESM_FORMAT**(_url_)
17681853
17691854
> 1. Assert: _url_ corresponds to an existing file.
Collapse file

‎doc/api/modules.md‎

Copy file name to clipboardExpand all lines: doc/api/modules.md
+12-1Lines changed: 12 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ require(X) from module at path Y
160160
a. LOAD_AS_FILE(Y + X)
161161
b. LOAD_AS_DIRECTORY(Y + X)
162162
c. THROW "not found"
163-
4. LOAD_SELF_REFERENCE(X, dirname(Y))
163+
4. If X begins with '#'
164+
a. LOAD_INTERAL_IMPORT(X, Y)
165+
4. LOAD_SELF_REFERENCE(X, Y)
164166
5. LOAD_NODE_MODULES(X, dirname(Y))
165167
6. THROW "not found"
166168
@@ -236,6 +238,15 @@ LOAD_PACKAGE_EXPORTS(DIR, X)
236238
12. Otherwise
237239
a. If RESOLVED is a file, load it as its file extension format. STOP
238240
13. Throw "not found"
241+
242+
LOAD_INTERNAL_IMPORT(X, START)
243+
1. Find the closest package scope to START.
244+
2. If no scope was found or the `package.json` has no "imports", return.
245+
3. let RESOLVED =
246+
fileURLToPath(PACKAGE_INTERNAL_RESOLVE(X, pathToFileURL(START)), as defined
247+
in the ESM resolver.
248+
4. If RESOLVED is not a valid file, throw "not found"
249+
5. Load RESOLVED as its file extension format. STOP
239250
```
240251

241252
## Caching
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+23-41Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const {
2121
NumberIsInteger,
2222
ObjectDefineProperty,
2323
ObjectKeys,
24-
StringPrototypeSlice,
2524
StringPrototypeStartsWith,
2625
Symbol,
2726
SymbolFor,
@@ -1097,16 +1096,9 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
10971096
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError);
10981097
E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError);
10991098
E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError);
1100-
E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => {
1101-
if (subpath === undefined) {
1102-
return `Invalid package name '${pkgPath}' imported from ${base}`;
1103-
} else if (base === undefined) {
1104-
assert(subpath !== '.');
1105-
return `Package subpath '${subpath}' is not a valid module request for ` +
1106-
`the "exports" resolution of ${pkgPath}${sep}package.json`;
1107-
}
1108-
return `Package subpath '${subpath}' is not a valid module request for ` +
1109-
`the "exports" resolution of ${pkgPath} imported from ${base}`;
1099+
E('ERR_INVALID_MODULE_SPECIFIER', (request, reason, base = undefined) => {
1100+
return `Invalid module "${request}" ${reason}${base ?
1101+
` imported from ${base}` : ''}`;
11101102
}, TypeError);
11111103
E('ERR_INVALID_OPT_VALUE', (name, value) =>
11121104
`The value "${String(value)}" is invalid for option "${name}"`,
@@ -1120,31 +1112,20 @@ E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
11201112
return `Invalid JSON in ${path} imported from ${message}`;
11211113
}, Error);
11221114
E('ERR_INVALID_PACKAGE_TARGET',
1123-
(pkgPath, key, subpath, target, base = undefined) => {
1124-
const relError = typeof target === 'string' &&
1115+
(pkgPath, key, target, isImport = false, base = undefined) => {
1116+
const relError = typeof target === 'string' && !isImport &&
11251117
target.length && !StringPrototypeStartsWith(target, './');
1126-
if (key === null) {
1127-
if (subpath !== '') {
1128-
return `Invalid "exports" target ${JSONStringify(target)} defined ` +
1129-
`for '${subpath}' in the package config ${pkgPath} imported from ` +
1130-
`${base}.${relError ? '; targets must start with "./"' : ''}`;
1131-
}
1132-
return `Invalid "exports" main target ${target} defined in the ` +
1133-
`package config ${pkgPath} imported from ${base}${relError ?
1134-
'; targets must start with "./"' : ''}`;
1135-
} else if (key === '.') {
1118+
if (key === '.') {
1119+
assert(isImport === false);
11361120
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
1137-
`in the package config ${pkgPath}${sep}package.json${relError ?
1138-
'; targets must start with "./"' : ''}`;
1139-
} else if (relError) {
1140-
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
1141-
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
1142-
`package config ${pkgPath}${sep}package.json; ` +
1143-
'targets must start with "./"';
1121+
`in the package config ${pkgPath}package.json${base ?
1122+
` imported from ${base}` : ''}${relError ?
1123+
'; targets must start with "./"' : ''}`;
11441124
}
1145-
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
1146-
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
1147-
`package config ${pkgPath}${sep}package.json`;
1125+
return `Invalid "${isImport ? 'imports' : 'exports'}" target ${
1126+
JSONStringify(target)} defined for '${key}' in the package config ${
1127+
pkgPath}package.json${base ? ` imported from ${base}` : ''}${relError ?
1128+
'; targets must start with "./"' : ''}`;
11481129
}, Error);
11491130
E('ERR_INVALID_PERFORMANCE_MARK',
11501131
'The "%s" performance mark has not been set', Error);
@@ -1293,15 +1274,16 @@ E('ERR_OUT_OF_RANGE',
12931274
msg += ` It must be ${range}. Received ${received}`;
12941275
return msg;
12951276
}, RangeError);
1277+
E('ERR_PACKAGE_IMPORT_NOT_DEFINED', (specifier, packagePath, base) => {
1278+
return `Package import specifier "${specifier}" is not defined${packagePath ?
1279+
` in package ${packagePath}package.json` : ''} imported from ${base}`;
1280+
}, TypeError);
12961281
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
1297-
if (subpath === '.') {
1298-
return `No "exports" main resolved in ${pkgPath}${sep}package.json`;
1299-
} else if (base === undefined) {
1300-
return `Package subpath '${subpath}' is not defined by "exports" in ${
1301-
pkgPath}${sep}package.json`;
1302-
}
1282+
if (subpath === '.')
1283+
return `No "exports" main defined in ${pkgPath}package.json${base ?
1284+
` imported from ${base}` : ''}`;
13031285
return `Package subpath '${subpath}' is not defined by "exports" in ${
1304-
pkgPath} imported from ${base}`;
1286+
pkgPath}package.json${base ? ` imported from ${base}` : ''}`;
13051287
}, Error);
13061288
E('ERR_REQUIRE_ESM',
13071289
(filename, parentPath = null, packageJsonPath = null) => {
@@ -1419,7 +1401,7 @@ E('ERR_UNKNOWN_FILE_EXTENSION',
14191401
E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError);
14201402
E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError);
14211403
E('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " +
1422-
'resolving ES modules, imported from %s', Error);
1404+
'resolving ES modules imported from %s', Error);
14231405
E('ERR_UNSUPPORTED_ESM_URL_SCHEME', 'Only file and data URLs are supported ' +
14241406
'by the default ESM loader', Error);
14251407

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.