Skip to content

Commit

Permalink
Fix: "Module not found" error causes esbuild-loader to crash with "Ca…
Browse files Browse the repository at this point in the history
…nnot read properties of undefined (reading 'useSourceMap')"
  • Loading branch information
Ivan Pantic committed Jan 22, 2024
1 parent 51685cd commit 74c538c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export default class EsbuildPlugin {
? modules[0]
: (modules as Set<webpack5.Module>).values().next().value as webpack5.Module
);
useSourceMap = firstModule.useSourceMap;
if (firstModule) {
useSourceMap = firstModule.useSourceMap;
}
},
);

Expand Down
11 changes: 11 additions & 0 deletions tests/specs/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,17 @@ export default testSuite(({ describe }, webpack: typeof webpack4 | typeof webpac
expect(exportedFunction('hello world')).toBe('hello world');
assertMinified(exportedFunction.toString());
});

test('can handle invalid webpack config', async () => {
await expect(build(
fixtures.blank,
(config) => {
config.entry = 'not-there.js';
configureEsbuildMinifyPlugin(config);
},
webpack,
)).resolves.toBeTruthy();
});
});

describe('CSS', ({ test }) => {
Expand Down

0 comments on commit 74c538c

Please sign in to comment.