Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
unabbreviate ERR_PACKAGE_PATH_NOT_EXPORTED
  • Loading branch information
guybedford committed Feb 4, 2020
commit fb97d9738839515e2ddf3072f83e48e767a5384c
4 changes: 2 additions & 2 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,8 @@ A non-context-aware native addon was loaded in a process that disallows them.

A given value is out of the accepted range.

<a id="ERR_PKG_PATH_NOT_EXPORTED"></a>
### `ERR_PKG_PATH_NOT_EXPORTED`
<a id="ERR_PACKAGE_PATH_NOT_EXPORTED"></a>
### `ERR_PACKAGE_PATH_NOT_EXPORTED`

The `package.json` [exports][] field does not export the requested subpath.
Because exports are encapsulated, private internal modules that are not exported
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
SymbolFor,
WeakMap,
} = primordials;
const sep = process.platform === 'win32' ? '\\' : '/';
const { sep } = require('path');

const messages = new Map();
const codes = {};
Expand Down Expand Up @@ -1243,7 +1243,7 @@ E('ERR_OUT_OF_RANGE',
msg += ` It must be ${range}. Received ${received}`;
return msg;
}, RangeError);
E('ERR_PKG_PATH_NOT_EXPORTED', (pkgPath, subpath) => {
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath) => {
if (subpath === '.') {
return `No "exports" main resolved in ${pkgPath}${sep}package.json`;
} else {
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const {
ERR_INVALID_PACKAGE_CONFIG,
ERR_INVALID_PACKAGE_TARGET,
ERR_INVALID_MODULE_SPECIFIER,
ERR_PKG_PATH_NOT_EXPORTED,
ERR_PACKAGE_PATH_NOT_EXPORTED,
ERR_REQUIRE_ESM
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
Expand Down Expand Up @@ -524,7 +524,7 @@ function applyExports(basePath, expansion) {
}
}

throw new ERR_PKG_PATH_NOT_EXPORTED(basePath, mappingKey);
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(basePath, mappingKey);
}

// This only applies to requests of a specific form:
Expand Down Expand Up @@ -593,7 +593,7 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
try {
return resolveExportsTarget(baseUrl, targetValue, subpath, mappingKey);
} catch (e) {
if (e.code !== 'ERR_PKG_PATH_NOT_EXPORTED' &&
if (e.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' &&
e.code !== 'ERR_INVALID_PACKAGE_TARGET')
throw e;
}
Expand All @@ -617,19 +617,19 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) {
return resolveExportsTarget(baseUrl, target[p], subpath,
mappingKey);
} catch (e) {
if (e.code !== 'ERR_PKG_PATH_NOT_EXPORTED') throw e;
if (e.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') throw e;
}
break;
case 'default':
try {
return resolveExportsTarget(baseUrl, target.default, subpath,
mappingKey);
} catch (e) {
if (e.code !== 'ERR_PKG_PATH_NOT_EXPORTED') throw e;
if (e.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') throw e;
}
}
}
throw new ERR_PKG_PATH_NOT_EXPORTED(
throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
StringPrototypeSlice(baseUrl.pathname, 0, -1), mappingKey + subpath);
}
throw new ERR_INVALID_PACKAGE_TARGET(
Expand Down
8 changes: 4 additions & 4 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void ThrowExportsNotFound(Environment* env,
const std::string msg = "Package subpath '" + subpath + "' is not defined" +
" by \"exports\" in " + pjson_url.ToFilePath() + " imported from " +
base.ToFilePath();
node::THROW_ERR_PKG_PATH_NOT_EXPORTED(env, msg.c_str());
node::THROW_ERR_PACKAGE_PATH_NOT_EXPORTED(env, msg.c_str());
}

void ThrowSubpathInvalid(Environment* env,
Expand Down Expand Up @@ -1001,7 +1001,7 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
Utf8Value code_utf8(env->isolate(),
code->ToString(context).ToLocalChecked());
Comment thread
guybedford marked this conversation as resolved.
Outdated
std::string code_str(*code_utf8, code_utf8.length());
if (code_str == "ERR_PKG_PATH_NOT_EXPORTED" ||
if (code_str == "ERR_PACKAGE_PATH_NOT_EXPORTED" ||
code_str == "ERR_INVALID_PACKAGE_TARGET") {
Comment thread
guybedford marked this conversation as resolved.
Outdated
continue;
}
Expand Down Expand Up @@ -1051,7 +1051,7 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
Utf8Value code_utf8(env->isolate(),
code->ToString(context).ToLocalChecked());
std::string code_str(*code_utf8, code_utf8.length());
if (code_str == "ERR_PKG_PATH_NOT_EXPORTED") continue;
if (code_str == "ERR_PACKAGE_PATH_NOT_EXPORTED") continue;
try_catch.ReThrow();
return Nothing<URL>();
}
Expand Down Expand Up @@ -1146,7 +1146,7 @@ Maybe<URL> PackageMainResolve(Environment* env,
}
std::string msg = "No \"exports\" main resolved in " +
pjson_url.ToFilePath();
node::THROW_ERR_PKG_PATH_NOT_EXPORTED(env, msg.c_str());
node::THROW_ERR_PACKAGE_PATH_NOT_EXPORTED(env, msg.c_str());
}
if (pcfg.has_main == HasMain::Yes) {
URL resolved(pcfg.main, pjson_url);
Expand Down
2 changes: 1 addition & 1 deletion src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void OnFatalError(const char* location, const char* message);
V(ERR_NON_CONTEXT_AWARE_DISABLED, Error) \
V(ERR_MODULE_NOT_FOUND, Error) \
V(ERR_OUT_OF_RANGE, RangeError) \
V(ERR_PKG_PATH_NOT_EXPORTED, Error) \
V(ERR_PACKAGE_PATH_NOT_EXPORTED, Error) \
V(ERR_SCRIPT_EXECUTION_INTERRUPTED, Error) \
V(ERR_SCRIPT_EXECUTION_TIMEOUT, Error) \
V(ERR_STRING_TOO_LONG, Error) \
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';

for (const [specifier, subpath] of undefinedExports) {
loadFixture(specifier).catch(mustCall((err) => {
strictEqual(err.code, 'ERR_PKG_PATH_NOT_EXPORTED');
strictEqual(err.code, 'ERR_PACKAGE_PATH_NOT_EXPORTED');
assertStartsWith(err.message, 'Package subpath ');
assertIncludes(err.message, subpath);
}));
Expand All @@ -113,7 +113,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js';
// of falling back to main
if (isRequire) {
loadFixture('pkgexports-main').catch(mustCall((err) => {
strictEqual(err.code, 'ERR_PKG_PATH_NOT_EXPORTED');
strictEqual(err.code, 'ERR_PACKAGE_PATH_NOT_EXPORTED');
assertStartsWith(err.message, 'No "exports" main ');
}));
}
Expand Down