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

[NEXT-1092] next build compile error regarding export worker #49059

Closed
1 task done
Kazzuk opened this issue May 1, 2023 · 22 comments · Fixed by #49311
Closed
1 task done

[NEXT-1092] next build compile error regarding export worker #49059

Kazzuk opened this issue May 1, 2023 · 22 comments · Fixed by #49311
Assignees
Labels
area: app App directory (appDir: true)

Comments

@Kazzuk
Copy link

Kazzuk commented May 1, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
Binaries:
  Node: 18.16.0
  npm: 9.5.1
  Yarn: N/A
  pnpm: 8.4.0
Relevant packages:
  next: 13.4.1-canary.2
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Package manager (npm, pnpm, Yarn), Static HTML Export (output: "export")

Link to the code that reproduces this issue

https://github.com/Kazzuk/reproduce

To Reproduce

  • Ensure output is set to "export" in next.config.js to cause error.
  • Run pnpm build.

Describe the Bug

Whenever output is set to "export" in next.config.js and you build the project you will be met with the below error. If I was to remove output from next.config.js the project compiles fine. As well if remove the dynamic routes (delete blog folder) from the project while output is set to "export" the project compiles fine.

> Build error occurred
Error: invariant: Undefined export worker for app dir, this is a bug in Next.js.
    at C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\export\index.js:506:27
    at Span.traceAsyncFn (C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\trace\trace.js:103:26)
    at C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\export\index.js:502:35
    at Array.map (<anonymous>)
    at C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\export\index.js:499:41
    at async Span.traceAsyncFn (C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\trace\trace.js:103:20)    
    at async C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\build\index.js:1887:17
    at async Span.traceAsyncFn (C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\trace\trace.js:103:20)    
    at async build (C:\Users\Kazuk\Documents\GitHub\reproduce\node_modules\.pnpm\next@13.4.1-canary.2_react-dom@18.2.0_react@18.2.0\node_modules\next\dist\build\index.js:143:29)

Expected Behavior

Build should be successful.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

From SyncLinear.com | NEXT-1092

@Kazzuk Kazzuk added the bug Issue was opened via the bug report template. label May 1, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label May 1, 2023
@mtnowl
Copy link

mtnowl commented May 2, 2023

It also seems to go away when you put getStaticParams in dynamic route pages.

@alarcndaniela
Copy link

I'm having the same issue

@detachedsoul
Copy link

I'm also having the same issue.

@rjruizes
Copy link

rjruizes commented May 2, 2023

In my case, fixing my generateStaticParams functions fixed the error. I have 3 dynamic segments in my URL, e.g. /[org]/[dept]/[unit].

[org]/layout.tsx: generateStaticParams returns array for possible values of `org`
  [dept]/layout.tsx: generateStaticParams returns array for possible values of `dept`
    [unit]/page.tsx: generateStaticParams returns array for possible values of `unit`

Doc: https://beta.nextjs.org/docs/api-reference/generate-static-params

Initially I had incorrect values in [unit]/page.tsx and I isolated the problem by removing files one at a time.

@mtnowl
Copy link

mtnowl commented May 3, 2023

@rjruizes Those child generateStaticParams calls are working for you? I'm getting this bug where the child generateStaticParams are being passed undefined parameters.

@alarcndaniela
Copy link

@rjruizes This is definitely the root cause for the error in my case, yesterday I moved the files one at a time to a new project and discovered it. Thank you!

@rjruizes
Copy link

rjruizes commented May 3, 2023

@mtnowl The params are defined for me. I pushed up an example repo to demo it working, see page.tsx.

@alarcndaniela
Copy link

I just discovered that in my case everytime I add a folder estructure like /dashboard/admin/companies/[id] the error pops up

@ytsruh
Copy link

ytsruh commented May 5, 2023

Same issue from me. Unable to use build / export whilst using a dyanmic route and client side component.

Error: invariant: Undefined export worker for app dir, this is a bug in Next.js.

@alarcndaniela
Copy link

I stoped using the last version of nextjs 13 with the experimental app directory and changed it to a project without app and src directory and the build was successfully made

@styfle styfle added kind: bug and removed bug Issue was opened via the bug report template. labels May 5, 2023
@styfle styfle self-assigned this May 5, 2023
@styfle styfle changed the title next build compile error regarding export worker [NEXT-1092] next build compile error regarding export worker May 5, 2023
@mdmathewdc
Copy link

mdmathewdc commented May 6, 2023

I am also facing the same issue with Next 13.4.1. The document suggestsgenerateStaticParams method to statically generate a dynamic route (https://nextjs.org/docs/app/api-reference/functions/generate-static-params).

But is there an option to make it dynamic if I don't know the props at build time? eg: In my application, I'm generating a unique UUID so that it can be shared as a link - https://xyz.app/play/UUID. How will export the app as a static site then?

The answer to this question is to export the component as a client component as discussed here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports#dynamic-fetching-with-client-components

But even if I export it as a client component, I still get this error.

@brandensilva
Copy link

brandensilva commented May 6, 2023

The same issue is occurring for me on 13.4.1 but I am doing nothing with params or dynamic routing atm. Only one server side fetch going on and its happening so something else perhaps causing it.

@mkarajohn
Copy link

mkarajohn commented May 7, 2023

I have this issue as well.

Simple reproduction repo: https://codesandbox.io/p/sandbox/hardcore-lehmann-w4hd2f

just run npm run build

If I just move the page.tsx back inside app the error does not come up. Come to think of it, for building it as an SPA, all I need is a single html page, which I can get by moving the page.tsx to the root of the app, but nonetheless, this error exists if only a catch-all route is in play. Maybe it should warn or something, if it's not supposed to be built like that.

If I want to run the app in development mode however I need to have the page.tsx inside the catch-all route, in order to simulate the SPA behaviour, so there is a discrepancy here.

Context

I am moving an existing CRA project over to Next. I have set up the app router so that I have a single catch-all root, like this:

src/
 |-app/
   |-[[...path]]/
   | |-page.tsx
   |-layout.tsx

I am trying to build it as a SPA using the output: 'export' option in the config.

The build fails and the out directory ends up having only a 404.html page.

Error

- info Linting and checking validity of types  
- info Collecting page data  
- info Generating static pages (3/3)
- info Finalizing page optimization  

Route (app)                                Size     First Load JS
┌ λ /[[...path]]                           1.4 kB         79.1 kB
└ ○ /favicon.ico                           0 B                0 B
+ First Load JS shared by all              77.7 kB
  ├ chunks/139-f94b65a583fb7f46.js         24.6 kB
  ├ chunks/2443530c-c1df3a32f9287dc4.js    50.5 kB
  ├ chunks/main-app-f3225843db279bbc.js    221 B
  └ chunks/webpack-33cf70d50500edbd.js     2.37 kB

Route (pages)                              Size     First Load JS
─ ○ /404                                   180 B          86.8 kB
+ First Load JS shared by all              86.6 kB
  ├ chunks/main-3a574163a2858406.js        84.1 kB
  ├ chunks/pages/_app-dec1a83570915fb0.js  195 B
  └ chunks/webpack-33cf70d50500edbd.js     2.37 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)


> Build error occurred
Error: invariant: Undefined export worker for app dir, this is a bug in Next.js.
    at /home/mitch/Workspace/next-projects/project/node_modules/next/dist/export/index.js:506:27
    at Span.traceAsyncFn (/home/mitch/Workspace/next-projects/project/node_modules/next/dist/trace/trace.js:103:26)
    at /home/mitch/Workspace/next-projects/project/node_modules/next/dist/export/index.js:502:35
    at Array.map (<anonymous>)
    at /home/mitch/Workspace/next-projects/project/node_modules/next/dist/export/index.js:499:41
    at async Span.traceAsyncFn (/home/mitch/Workspace/next-projects/project/node_modules/next/dist/trace/trace.js:103:20)
    at async /home/mitch/Workspace/next-projects/project/node_modules/next/dist/build/index.js:1887:17
    at async Span.traceAsyncFn (/home/mitch/Workspace/next-projects/project/node_modules/next/dist/trace/trace.js:103:20)
    at async build (/home/mitch/Workspace/next-projects/project/node_modules/next/dist/build/index.js:143:29)

Setup info

    Operating System:
      Platform: linux
      Arch: x64
      Version: #41~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 31 16:00:14 UTC 2
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.1-canary.2
      eslint-config-next: 13.4.1
      react: 18.2.0
      react-dom: 18.2.0

@jayalmaraz
Copy link

jayalmaraz commented May 8, 2023

+1 getting this error on 13.4.1 & have been getting it since 13.3.2

> Build error occurred
Error: invariant: Undefined export worker for app dir, this is a bug in Next.js.

MCVE: https://github.com/jayalmaraz/20230508-next-13-app-router-static-export-bug

Obviously generateStaticParams isn't a real solution. We are relying on Dynamic Route Segments with Client Component data fetching (documented supported by Static Export), and expecting it to work

macOS 12.6.2
node 16.20.0

@kodiakhq kodiakhq bot closed this as completed in #49311 May 8, 2023
kodiakhq bot pushed a commit that referenced this issue May 8, 2023
- Reverts #48291
- Fixes #49059 
- TODO: move these tests to `./tests/e2e/*` to avoid flakes (that will be a follow up PR)
fix NEXT-1092
@styfle
Copy link
Member

styfle commented May 8, 2023

This is fixed on the canary channel.

You can try it today with npm install next@canary, thanks!

@Yehorchik
Copy link

@styfle i just tried it on 13.4.2-canary.3 and it's still has the same issue :(

@ytsruh
Copy link

ytsruh commented May 9, 2023

@styfle i just tried it on 13.4.2-canary.3 and it's still has the same issue :(

Works fine for me

@styfle
Copy link
Member

styfle commented May 9, 2023

@Yehorchik You might have a different issue. See #48022

@ytsruh Thanks for confirming 👍

@nhat-em-wick
Copy link

@styfle thanks

@Sagar848
Copy link

This is fixed on the canary channel.

You can try it today with npm install next@canary, thanks!

Thanks, this worked

@brandensilva
Copy link

Also confirmed the fix, thanks.

@oldbettie
Copy link

confirmed fixed in v13.4.4

@vercel vercel locked as resolved and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true)
Projects
None yet
Development

Successfully merging a pull request may close this issue.