next.js: [NEXT-1092] `next build` compile error regarding export worker
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” innext.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
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 22 (2 by maintainers)
This is fixed on the canary channel.
You can try it today with
npm install next@canary
, thanks!I am also facing the same issue with Next 13.4.1. The document suggests
generateStaticParams
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.
In my case, fixing my
generateStaticParams
functions fixed the error. I have 3 dynamic segments in my URL, e.g./[org]/[dept]/[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.+1 getting this error on
13.4.1
& have been getting it since13.3.2
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@mtnowl The params are defined for me. I pushed up an example repo to demo it working, see page.tsx.