privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.56k stars 108 forks source link

import meta empty object #372

Closed Elanza-48 closed 4 months ago

Elanza-48 commented 4 months ago

Problem

When using with webpack5 having web worker, the import.meta is coming empty. So creating new web worker object is failing. Capture

Expected behavior

import.meta should not be empty.

Minimal reproduction URL

private project

Version

v4.1.0

Node.js version

v18.19.1

Package manager

npm

Operating system

Windows

Contributions

fasiha commented 1 month ago

I'm running into this issue as well but I think it's possibly indicative of a broader issue. @privatenumber can I ask, does esbuild-loader/esbuild support this webpack new Worker paradigm? Based on https://github.com/evanw/esbuild/issues/312 I think the answer is "not yet"?

To check, I cloned someone's minimal repo showing how to use WebWorkers with TypeScript and plain Webpack+Babel (main master branch of https://github.com/fasiha/web-worker-ts-webpack-test), and tried removing Babel and using esbuild-loader instead (in testing-esbuild branch) and I can confirm @Elanza-48's observations:

  1. import.meta.url is undefined when using esbuild-loader but works fine using babel
  2. the WebWorker itself doesn't work using esbuild-loader but again worked fine using babel. In fact, with esbuild-loader, it looks like the WebWorker's code in foo.worker.ts is never transpiled, since I can't find the text snippet inside it (42 WAS HERE) anywhere in the built output.

If the answer is "esbuild & esbuild-loader don't support Webpack WebWorkers" then this all makes sense and I'm sorry for making noise!

My info:

privatenumber commented 1 month ago

This is a closed issue because a minimal reproduction was not provided.

Please open a new issue if it's a verified bug.

For help, you can join my sponsorship program.