diff --git a/packages/commonjs/src/index.js b/packages/commonjs/src/index.js index dedda0a01..99a92a8d5 100644 --- a/packages/commonjs/src/index.js +++ b/packages/commonjs/src/index.js @@ -140,15 +140,15 @@ export default function commonjs(options = {}) { !isEsModule && (dynamicRequireModules.has(normalizedId) || strictRequiresFilter(id)); const checkDynamicRequire = (position) => { - const normalizedRequireRoot = normalizePathSlashes(dynamicRequireRoot); + const normalizedDynamicRequireRoot = normalizePathSlashes(dynamicRequireRoot); - if (normalizedId.indexOf(normalizedRequireRoot) !== 0) { + if (normalizedId.indexOf(normalizedDynamicRequireRoot) !== 0) { this.error( { code: 'DYNAMIC_REQUIRE_OUTSIDE_ROOT', normalizedId, - dynamicRequireRoot, - message: `"${normalizedId}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${normalizedRequireRoot}". You should set dynamicRequireRoot to "${dirname( + normalizedDynamicRequireRoot, + message: `"${normalizedId}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${normalizedDynamicRequireRoot}". You should set dynamicRequireRoot to "${dirname( normalizedId )}" or one of its parent directories.` }, diff --git a/packages/commonjs/test/test.js b/packages/commonjs/test/test.js index 948151c0e..fc8d4934c 100644 --- a/packages/commonjs/test/test.js +++ b/packages/commonjs/test/test.js @@ -733,8 +733,8 @@ test('throws when there is a dynamic require from outside dynamicRequireRoot', a t.like(error, { message: `"${id}" contains dynamic require statements but it is not within the current dynamicRequireRoot "${dynamicRequireRoot}". You should set dynamicRequireRoot to "${minimalDynamicRequireRoot}" or one of its parent directories.`, pluginCode: 'DYNAMIC_REQUIRE_OUTSIDE_ROOT', - id, - dynamicRequireRoot + normalizedId: id, + normalizedDynamicRequireRoot: dynamicRequireRoot }); });