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

Code with a worker fails to build under the edge runtime, even if it's dead code. #65069

Open
uonr opened this issue Apr 25, 2024 · 0 comments
Open
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@uonr
Copy link

uonr commented Apr 25, 2024

Link to the code that reproduces this issue

https://github.com/uonr/nextjs-edge-worker-issue-repoducetion/blob/master/src/app/FromWorker.tsx

To Reproduce

  1. Build it

Current vs. Expected behavior

Expected build success, but:

> [email protected] build
> next build

  ▲ Next.js 14.2.3

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
   Collecting page data  ./Users/user/Repositories/repoduction-worker-issue/.next/server/edge-runtime-webpack.js:1
(()=>{"use strict";var e={},r={};function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}},l=!0;try{e[o](i,i.exports,t),l=!1}finally{l&&delete r[o]}return i.exports}t.m=e,(()=>{var e=[];t.O=(r,o,n,i)=>{if(o){i=i||0;for(var l=e.length;l>0&&e[l-1][2]>i;l--)e[l]=e[l-1];e[l]=[o,n,i];return}for(var a=1/0,l=0;l<e.length;l++){for(var[o,n,i]=e[l],u=!0,f=0;f<o.length;f++)a>=i&&Object.keys(t.O).every(e=>t.O[e](o[f]))?o.splice(f--,1):(u=!1,i<a&&(a=i));if(u){e.splice(l--,1);var s=n();void 0!==s&&(r=s)}}return r}})(),t.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},t.e=()=>Promise.resolve(),t.u=e=>""+e+".js",t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.p="/_next/",(()=>{t.b=document.baseURI||self.location.href;var e={993:0};t.O.j=r=>0===e[r];var r=(r,o)=>{var n,i,[l,a,u]=o,f=0;if(l.some(r=>0!==e[r])){for(n in a)t.o(a,n)&&(t.m[n]=a[n]);if(u)var s=u(t)}for(r&&r(o);f<l.length;f++)i=l[f],t.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return t.O(s)},o=self.webpackChunk_N_E=self.webpackChunk_N_E||[];o.forEach(r.bind(null,0)),o.push=r.bind(null,o.push.bind(o))})()})();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

ReferenceError: document is not defined
    at /Users/user
/Repositories/repoduction-worker-issue/.next/server/edge-runtime-webpack.js:1:1156
    at /Users/user/Repositories/repoduction-worker-issue/.next/server/edge-runtime-webpack.js:1:1530
    at /Users/user/Repositories/repoduction-worker-issue/.next/server/edge-runtime-webpack.js:1:1534
    at Script.runInContext (node:vm:148:12)
    at runInContext (node:vm:300:6)
    at evaluateInContext (/Users/user/Repositories/repoduction-worker-issue/node_modules/next/dist/server/web/sandbox/context.js:403:38)
    at getRuntimeContext (/Users/user/Repositories/repoduction-worker-issue/node_modules/next/dist/server/web/sandbox/sandbox.js:71:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/user/Repositories/repoduction-worker-issue/node_modules/next/dist/build/utils.js:1089:29
    at async Span.traceAsyncFn (/Users/user/Repositories/repoduction-worker-issue/node_modules/next/dist/trace/trace.js:154:20)

> Build error occurred
Error: Failed to collect page data for /
    at /Users/user/Repositories/repoduction-worker-issue/node_modules/next/dist/build/utils.js:1268:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}
   Collecting page data

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: N/A
  pnpm: 8.15.5
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.3.0
  react-dom: 18.3.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

It looks like a code generation issue, the project that found this issue used babel instead of swc, but had the exact same problem

@uonr uonr added the bug Issue was opened via the bug report template. label Apr 25, 2024
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant