diff --git a/packages/node-resolve/src/index.js b/packages/node-resolve/src/index.js index 9a73b5cfb..0da8f54f2 100644 --- a/packages/node-resolve/src/index.js +++ b/packages/node-resolve/src/index.js @@ -57,6 +57,12 @@ export function nodeResolve(opts = {}) { let { dedupe } = options; let rollupOptions; + if (moduleDirectories.some((name) => name.includes('/'))) { + throw new Error( + '`moduleDirectories` option must only contain directory names. If you want to load modules from somewhere not supported by the default module resolution algorithm, see `modulePaths`.' + ); + } + if (typeof dedupe !== 'function') { dedupe = (importee) => options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee)); diff --git a/packages/node-resolve/test/test.js b/packages/node-resolve/test/test.js index 15bec442d..a9faff3c7 100755 --- a/packages/node-resolve/test/test.js +++ b/packages/node-resolve/test/test.js @@ -273,20 +273,16 @@ test('allows custom moduleDirectories with legacy customResolveOptions.moduleDir t.snapshot(warnings); }); -test('custom moduleDirectories do not support nested dependencies', async (t) => { - const warnings = []; - const bundle = await rollup({ - input: 'custom-module-path/main.js', - onwarn: (warning) => warnings.push(warning), - plugins: [ +test('moduleDirectories option rejects paths that contain a slash', async (t) => { + t.throws( + () => nodeResolve({ - moduleDirectories: [join(process.cwd(), 'custom-module-path/node_modules')] - }) - ] - }); - - t.is(warnings.length, 1); - t.is(bundle.cache.modules.length, 2); + moduleDirectories: ['some/path'] + }), + { + message: /must only contain directory names/ + } + ); }); test('allows custom modulePaths', async (t) => {