Skip to content

Commit 9da2f9c

Browse files
committed
Handle ERR_PACKAGE_PATH_NOT_EXPORTED gracefully
Fixes #104 Closes #108
1 parent e18e8ae commit 9da2f9c

File tree

7 files changed

+35
-0
lines changed

7 files changed

+35
-0
lines changed

index.js

+4
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/node_modules/esm-module-without-svelte-config/index.js

Whitespace-only changes.

test/node_modules/esm-module-without-svelte-config/package.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/esm-widget/index.js

Whitespace-only changes.

test/node_modules/esm-widget/package.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/esm-widget/src/Widget.html

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

+16
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)