Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Module not found" error causes esbuild-loader to crash with "Cannot read properties of undefined (reading 'useSourceMap')" #356

Closed
2 tasks
panta82 opened this issue Jan 22, 2024 · 3 comments · Fixed by #357
Labels
bug Something isn't working pr welcome

Comments

@panta82
Copy link
Contributor

panta82 commented Jan 22, 2024

Problem

When there is a problem with module resolution during build, webpack emits "finishModules" event with an empty set.

esbuild-loader responds to this event by trying to extract useSourceMap. Since it is given an empty set, it crashes on this line: https://github.com/privatenumber/esbuild-loader/blob/develop/src/plugin.ts#L212

Suggested fix:

    compilation.hooks.finishModules.tap(
      pluginName,
      (modules) => {
        const firstModule = Array.isArray(modules) ? modules[0] : modules.values().next().value;
        if (firstModule) {
          useSourceMap = firstModule.useSourceMap;
        }
      }
    );

Expected behavior

Webpack is able to finish and report the actual error.

Minimal reproduction URL

https://stackblitz.com/edit/node-t2tcae?file=webpack.config.js,package.json&view=editor

Version

4.0.2

Node.js version

16.20.0

Package manager

npm

Operating system

Linux

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@panta82 panta82 added bug Something isn't working pending triage labels Jan 22, 2024
@privatenumber
Copy link
Owner

Nice catch!

Would you mind opening a PR with fix + test?

@panta82
Copy link
Contributor Author

panta82 commented Jan 22, 2024

I wouldn't mind. I mostly didn't because I don't have this project set up, and testing this seems like it would be tricky.
Let me check it out, and I'll let you know if I can handle it.

@panta82
Copy link
Contributor Author

panta82 commented Jan 22, 2024

Figured it out, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants