Repository: next.js
Issue: Error: Cannot find module '/path/to/repo/dist/packages/package-web/.next/server/chunks/lib/worker.js'
Labels: bug

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 8.6.2
    Relevant Packages:
      next: 13.4.9-canary.2
      eslint-config-next: 13.4.6
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A
```


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

App Router

### Link to the code that reproduces this issue or a replay of the bug

Let me know if needed, not sure it's easy to reproduce as I don't understand what is wrong.

### To Reproduce

So in the beginning, I was having this error. Try to resolve it by upgrading to latest next version, but it was still happening.
```
    ✖  nx run project-name-web:build:production
       - info Loaded env from /path/to/repo/packages/project-name-web/.env.local
       - info Loaded env from /path/to/repo/packages/project-name-web/.env
       - warn You have enabled experimental feature (serverActions) in next.config.js.
       - warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
       
       - info Creating an optimized production build...
       - warn Compiled with warnings
       
       ../../node_modules/keyv/src/index.js
       Critical dependency: the request of a dependency is an expression
       
       Import trace for requested module:
       ../../node_modules/keyv/src/index.js
       ../../node_modules/cacheable-request/src/index.js
       ../../node_modules/got/dist/source/core/index.js
       ../../node_modules/got/dist/source/create.js
       ../../node_modules/got/dist/source/index.js
       ../../node_modules/@mapbox/mapbox-sdk/lib/node/node-layer.js
       ../../node_modules/@mapbox/mapbox-sdk/lib/node/node-client.js
       ../../node_modules/@mapbox/mapbox-sdk/lib/client.js
       ../../node_modules/@mapbox/mapbox-sdk/index.js
       ../../node_modules/@mapbox/mapbox-gl-geocoder/lib/index.js
       ./app/components/client/Map/MapSearch.tsx
       
       - info Skipping linting
       - info Checking validity of types...
       - info Collecting page data...
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       Static worker unexpectedly exited with code: 1 and signal: null
       - info Generating static pages (0/13)
       - info Generating static pages (3/13)
       - info Generating static pages (6/13)
       - info Generating static pages (9/13)
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       Static worker unexpectedly exited with code: 1 and signal: null
       Static worker unexpectedly exited with code: 1 and signal: null
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       
       node:internal/event_target:1012
         process.nextTick(() => { throw err; });
                                  ^
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       Error: Cannot find module '/path/to/repo/dist/packages/project-name-web/.next/server/chunks/lib/worker.js'
           at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15)
           at Module._load (node:internal/modules/cjs/loader:920:27)
           at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
           at MessagePort.<anonymous> (node:internal/main/worker_thread:164:24)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
       Emitted 'error' event on Worker instance at:
           at [kOnErrorMessage] (node:internal/worker:300:10)
           at [kOnMessage] (node:internal/worker:311:37)
           at MessagePort.<anonymous> (node:internal/worker:212:57)
           at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
           at exports.emitMessage (node:internal/per_context/messageport:23:28)
           at MessagePort.callbackTrampoline (node:internal/async_hooks:130:17)
           at [kOnExit] (node:internal/worker:278:5)
           at Worker.<computed>.onexit (node:internal/worker:209:20)
           at Worker.callbackTrampoline (node:internal/async_hooks:130:17) {
         code: 'MODULE_NOT_FOUND',
         requireStack: []
       }
       
       Node.js v18.16.0
       
       > Build error occurred
       Error: Call retries were exceeded
           at ChildProcessWorker.initialize (/path/to/repo/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)
           at ChildProcessWorker._onExit (/path/to/repo/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)
           at ChildProcess.emit (node:events:513:28)
           at ChildProcess.emit (node:domain:489:12)
           at ChildProcess._handle.onexit (node:internal/child_process:291:12) {
         type: 'WorkerError'
       }
       Error occurred while trying to run the npx next build 
       Error: Command failed: npx next build 
           at checkExecSyncError (node:child_process:885:11)
           at execSync (node:child_process:957:15)
           at /path/to/repo/node_modules/@nx/next/src/executors/build/build.impl.js:46:42
           at Generator.next (<anonymous>)
           at /path/to/repo/node_modules/tslib/tslib.js:167:75
           at new Promise (<anonymous>)
           at Object.__awaiter (/path/to/repo/node_modules/tslib/tslib.js:163:16)
           at buildExecutor (/path/to/repo/node_modules/@nx/next/src/executors/build/build.impl.js:20:20)
           at /path/to/repo/node_modules/nx/src/command-line/run/run.js:113:23
```
So I was going to report a bug, but I try next@canary and now I have a new bug for tsx syntax?
```
    ✖  nx run project-name-web:build:production
       - info Loaded env from /path/to/repo/packages/project-name-web/.env.local
       - info Loaded env from /path/to/repo/packages/project-name-web/.env
       - warn You have enabled experimental feature (serverActions) in next.config.js.
       - warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
       
       - info Creating an optimized production build...
       Failed to compile.
       
       ../project-name-ui/src/lib/Box/Box.tsx
       Module parse failed: Unexpected token (7:7)
       You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
       | import Flex, { FlexProps } from "../Flex/Flex";
       | 
       > export type BoxProps = FlexProps & AriaAttributes;
       | 
       | const BoxElement = styled(Flex)`
       
       Import trace for requested module:
       ../project-name-ui/src/lib/Box/Box.tsx
       ../project-name-ui/src/index.ts
       ./app/[locale]/buildings/[id]/schema/page.tsx
       
       ../project-name-ui/src/lib/Button/Button.tsx
       Module parse failed: Unexpected token (7:7)
       You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
       | import { State } from "../Theme/Theme.types";
       | 
       > export enum ButtonSize {
       |        Sm = "sm",
       |        Md = "md",
       
       Import trace for requested module:
       ../project-name-ui/src/lib/Button/Button.tsx
       ../project-name-ui/src/lib/Button/index.ts
       ../project-name-ui/src/index.ts
       ./app/[locale]/buildings/[id]/schema/page.tsx
       
       ../project-name-ui/src/lib/ColorPicker/ColorPicker.tsx
       Module parse failed: Unexpected token (7:7)
       You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
       | import ColorTag from "./ColorTag";
       | 
       > export type ColorPickerProps = {
       |        colors: string[];
       | };
       
       Import trace for requested module:
       ../project-name-ui/src/lib/ColorPicker/ColorPicker.tsx
       ../project-name-ui/src/lib/ColorPicker/index.ts
       ../project-name-ui/src/index.ts
       ./app/[locale]/buildings/[id]/schema/page.tsx
       
       ../project-name-ui/src/lib/ColorPicker/ColorTag.tsx
       Module parse failed: Unexpected token (6:7)
       You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
       | import Flex, { FlexProps } from "../Flex/Flex";
       | 
       > export type ColorTagProps = {
       |        color: string;
       |        selected?: boolean;
       
       Import trace for requested module:
       ../project-name-ui/src/lib/ColorPicker/ColorTag.tsx
       ../project-name-ui/src/lib/ColorPicker/index.ts
       ../project-name-ui/src/index.ts
       ./app/[locale]/buildings/[id]/schema/page.tsx
       
       ../project-name-ui/src/lib/Dialog/Dialog.tsx
       Module parse failed: The keyword 'interface' is reserved (7:0)
       You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
       | import { Flex } from "../Flex/Flex";
       | 
       > interface DialogCSSProps {
       |        width?: string;
       |        height?: string;
       
       Import trace for requested module:
       ../project-name-ui/src/lib/Dialog/Dialog.tsx
       ../project-name-ui/src/lib/Dialog/index.ts
       ../project-name-ui/src/index.ts
       ./app/[locale]/buildings/[id]/schema/page.tsx
       
       
       > Build failed because of webpack errors
       Error occurred while trying to run the npx next build 
       Error: Command failed: npx next build 
           at checkExecSyncError (node:child_process:885:11)
           at execSync (node:child_process:957:15)
           at /path/to/repo/node_modules/@nx/next/src/executors/build/build.impl.js:49:42
           at Generator.next (<anonymous>)
           at /path/to/repo/node_modules/tslib/tslib.js:169:75
           at new Promise (<anonymous>)
           at Object.__awaiter (/path/to/repo/node_modules/tslib/tslib.js:165:16)
           at buildExecutor (/path/to/repo/node_modules/@nx/next/src/executors/build/build.impl.js:20:20)
           at /path/to/repo/node_modules/nx/src/command-line/run/run.js:101:23
```


### Describe the Bug

Because our app we are working is still small, we decide to port all our routes to the app directory. That was done and serving the app was not perfect but working. Tho, when we are trying to build our app, here where this log appear. We don't have static page, so we don't understand why the process happen. 

Updating next to canary, change the error for a typescript syntax error which isn't an error. The code is fine and shouldn't be an issue. 

### Expected Behavior

Next being able to build ? 

### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

_No response_