diff --git a/src/core/importType.js b/src/core/importType.js index 6e4ac9a4da..d40bf9fbc9 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -29,7 +29,7 @@ export function isExternalModule(name, settings, path, context) { if (arguments.length < 4) { throw new TypeError('isExternalModule: name, settings, path, and context are all required'); } - return isModule(name) && isExternalPath(name, settings, path, getContextPackagePath(context)); + return (isModule(name) || isScopedModule(name)) && isExternalPath(name, settings, path, getContextPackagePath(context)); } export function isExternalModuleMain(name, settings, path, context) { diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 0dcd5266bb..f0350ecb8f 100644 --- a/tests/src/core/importType.js +++ b/tests/src/core/importType.js @@ -234,11 +234,21 @@ describe('importType(name)', function () { it('`isExternalModule` works with windows directory separator', function () { const context = testContext(); expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true); + expect(isExternalModule('@foo/bar', {}, 'E:\\path\\to\\node_modules\\@foo\\bar', context)).to.equal(true); expect(isExternalModule('foo', { 'import/external-module-folders': ['E:\\path\\to\\node_modules'], }, 'E:\\path\\to\\node_modules\\foo', context)).to.equal(true); }); + it('`isExternalModule` works with unix directory separator', function () { + const context = testContext(); + expect(isExternalModule('foo', {}, '/path/to/node_modules/foo', context)).to.equal(true); + expect(isExternalModule('@foo/bar', {}, '/path/to/node_modules/@foo/bar', context)).to.equal(true); + expect(isExternalModule('foo', { + 'import/external-module-folders': ['/path/to/node_modules'], + }, '/path/to/node_modules/foo', context)).to.equal(true); + }); + it('correctly identifies scoped modules with `isScopedModule`', () => { expect(isScopedModule('@/abc')).to.equal(false); expect(isScopedModule('@/abc/def')).to.equal(false);