Skip to content

[Bug Report]: ReferenceError: __filename is not defined #2275

@felixmosh

Description

@felixmosh

System Info

System:
OS: macOS 13.2.1
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 345.54 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - ~/Library/Caches/fnm_multishells/8168_1678870975199/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.11.0 - ~/Library/Caches/fnm_multishells/8168_1678870975199/bin/npm
Watchman: 2023.02.06.00 - /usr/local/bin/watchman
Browsers:
Chrome: 111.0.5563.64
Firefox: 111.0
Safari: 16.3

Details

When bundling a code such as

const highlightWorker = new Worker(
  /* webpackChunkName: "highlight-worker" */ new URL('./worker.ts', import.meta.url)
);

it generates a code that using __filename even though the target is web.

a = new Worker(new URL("./worker.ts",n("url").pathToFileURL(__filename).toString())))

Reproduce link

No response

Reproduce Steps

create a bundle with an entry of

const highlightWorker = new Worker(
  /* webpackChunkName: "highlight-worker" */ new URL('./worker.ts', import.meta.url)
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions