Skip to content

Commit 22a941e

Browse files
committed
Handle ERR_PACKAGE_PATH_NOT_EXPORTED gracefully
Fixes #104 Closes #108
1 parent e18e8ae commit 22a941e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ function tryResolve(pkg, importer) {
5050
return relative.resolve(pkg, importer);
5151
} catch (err) {
5252
if (err.code === 'MODULE_NOT_FOUND') return null;
53+
if (err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
54+
console.warn(`WARNING: Could not read svelte config from ${pkg}. Reason: ${err.message}`);
55+
return null;
56+
}
5357
throw err;
5458
}
5559
}

test/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ describe('rollup-plugin-svelte', () => {
3333
);
3434
});
3535

36+
it('ignores esm module not exporting package.json', () => {
37+
const { resolveId } = plugin();
38+
assert.equal(
39+
resolveId('esm-module-without-svelte-config', path.resolve('test/foo/main.js')),
40+
null
41+
);
42+
});
43+
44+
it('resolves esm module exporting package.json', () => {
45+
const { resolveId } = plugin();
46+
assert.equal(
47+
resolveId('esm-widget', path.resolve('test/foo/main.js')),
48+
path.resolve('test/node_modules/esm-widget/src/Widget.html')
49+
);
50+
});
51+
3652
it('ignores virtual modules', () => {
3753
const { resolveId } = plugin();
3854
assert.equal(

0 commit comments

Comments
 (0)