Web workers do not work when runtime is edge
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/jauniusmentimeter/reproduction-app
To Reproduce
- Start the application with next dev command
- Open the page http://localhost:3000
- The error "document is not defined is returned from the server"
- Open
app/page.tsxand change runtime tonodejsinstead ofedge. The error is not returned anymore.
Current vs. Expected behavior
Web workers do not work when runtime is set to edge. They should work in the same way as on nodejs runtime, since they are running on the client.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020
Available memory (MB): 16384
Available CPU cores: 10
Binaries:
Node: 20.11.0
npm: 9.5.1
Yarn: 1.22.21
pnpm: 9.5.0
Relevant Packages:
next: 15.0.0-canary.72 // Latest available version is detected (15.0.0-canary.72).
eslint-config-next: N/A
react: 19.0.0-rc.0
react-dom: 19.0.0-rc.0
typescript: 5.3.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Runtime, Webpack
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local), Vercel (Deployed)
Additional context
For some reason document is trying to be accessed on server environment when web worker code exist:
here is the place in .next/server/edge-runtime-webpack.js that is failing:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction app, run it with next dev, and compare app/page.tsx using the edge and nodejs runtimes. Inspect the generated .next/server/edge-runtime-webpack.js location shown in the report; done means the web worker runs under the edge runtime without the server-side document is not defined error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs, react, typescript
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100