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

Error: Cannot find module 'next/dist/compiled/jest-worker' - On Docker #48173

Closed
1 task done
devhady opened this issue Apr 9, 2023 · 43 comments · Fixed by #48513
Closed
1 task done

Error: Cannot find module 'next/dist/compiled/jest-worker' - On Docker #48173

devhady opened this issue Apr 9, 2023 · 43 comments · Fixed by #48513
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@devhady
Copy link

devhady commented Apr 9, 2023

Verify canary release

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

Provide environment information

Error: Cannot find module 'next/dist/compiled/jest-worker'
Require stack:
- /app/node_modules/next/dist/server/lib/squoosh/main.js
- /app/node_modules/next/dist/server/image-optimizer.js
- /app/node_modules/next/dist/server/next-server.js
- /app/server.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
    at Function.mod._resolveFilename (/app/node_modules/next/dist/build/webpack/require-hook.js:23:32)
    at Function.Module._load (node:internal/modules/cjs/loader:871:27)
    at Module.require (node:internal/modules/cjs/loader:1098:19)
    at require (node:internal/modules/cjs/helpers:108:18)
    at Object.<anonymous> (/app/node_modules/next/dist/server/lib/squoosh/main.js:8:19)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/app/node_modules/next/dist/server/lib/squoosh/main.js',
    '/app/node_modules/next/dist/server/image-optimizer.js',
    '/app/node_modules/next/dist/server/next-server.js',
    '/app/server.js'
  ]
}

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

App directory (appDir: true), Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/Storxy/storxy-business-erp

To Reproduce

Trying to dockerize next application using with docker and the docker file can be found on the repo but it throws an errors when ever I run the containers and visit any page that contain an optimized image while sharp is already been installed and the image not shown

Describe the Bug

images not working in docker apps

Expected Behavior

to show optimized image?

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@devhady devhady added the bug Issue was opened via the bug report template. label Apr 9, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Runtime Related to Node.js or Edge Runtime with Next.js. labels Apr 9, 2023
@yassinebridi
Copy link

the same issue next@13.3.0

@phongitus
Copy link

phongitus commented Apr 10, 2023

the same next@13.0.0 .
I've been traced for few hours and my final solution is re-deploy using old image (1-2 days before it happens).

@Podfelix
Copy link

┌─[zhuxian@zhuxiandeMacBook-Pro] - [~/Documents/projects/learn/next-app] - [Mon Apr 10, 10:03]
└─[$]> next info

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64
Binaries:
  Node: 16.17.1
  npm: 9.6.2
  Yarn: 1.22.19
  pnpm: 8.1.0
Relevant packages:
  next: 13.3.0
  eslint-config-next: 13.3.0
  react: 18.2.0
  react-dom: 18.2.0

warn - Latest canary version not detected, detected: "13.3.0", newest: "13.3.1-canary.3".
Please try the latest canary version (npm install next@canary) to confirm the issue still exists before creating a new issue.
Read more - https://nextjs.org/docs/messages/opening-an-issue

@kelvin-du
Copy link

Try to downgrade sharp to ^0.31.3. It works for me.

@phongitus
Copy link

Try to downgrade sharp to ^0.31.3. It works for me.

I've tried 0.31.3 and 0.30.7. Both is not work for me

@axelhzf
Copy link

axelhzf commented Apr 10, 2023

I am having the same problem, it looks like the bug was introduce in v13.2.5-canary.27. I think the problem was introduced with this #47788

Previous version, v13.2.5-canary.26, works for me.

@phongitus
Copy link

phongitus commented Apr 11, 2023

We've updated node18-alpine in Dockerfile, and next v13.2.4, it works for me.

@rahul799
Copy link

use next@13.2.4 and the issue will be fixed.

@OmkoBass
Copy link

Downgrade next to 13.2.4 and it should work fine. It didn't work for me on 13.3.0. I've also tried downgrading sharp but to no avail.

Fraser27 pushed a commit to Fraser27/nextjs13-ssr-sample that referenced this issue Apr 11, 2023
@diegoaguilar
Copy link

Was this reported as a bug?

@motopods
Copy link
Contributor

same issue 13.3.1-canary.4

@nhatncb
Copy link

nhatncb commented Apr 12, 2023

same issue with #48077 and there is a workaround.

Tesin added a commit to Tesin/EVT-Challenge that referenced this issue Apr 13, 2023
Tesin added a commit to Tesin/EVT-Challenge that referenced this issue Apr 13, 2023
* [EVT-003] BUG: vercel/next.js#48173

* {EVT-003] Update lock file
@didemkkaslan
Copy link
Contributor

next 13.2.4 didn't work for me, images are not showing up in production

@bogoevskid
Copy link

Had the same issue with loading images on an app hosted with Amplify and downgrading next to 13.2.4 solved it for me

Yasamato added a commit to Yasamato/bvsr-landing-page that referenced this issue Apr 16, 2023
@RiccardoBiosas
Copy link

I can confirm that downgrading to next 13.2.4 worked for me (I am using node:18.14.0-alpine as a base docker image)

ijjk pushed a commit that referenced this issue Apr 18, 2023
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation or adding/fixing Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md



## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change
-->

### What?
This PR fixes the issue where using `output: "standalone"` breaks
`next/image`, `opengraph-image.tsx`,... (those that use
`image-optimizer`), which was introduced by #47208 as it added
`next/dist/compiled/jest-worker` to `ignores`.

### How?
Dynamically import `squoosh` so that it does not throw.

Fixes #48077
Fixes #48173
@wowissu
Copy link

wowissu commented May 8, 2023

Got same error on nextjs 13.3.0, node:18-alpine

Error: Cannot find module 'next/dist/compiled/jest-worker'

@ivoba
Copy link

ivoba commented Jun 1, 2023

Works for me now with: 13.3.5-canary.

@kyun
Copy link

kyun commented Jun 1, 2023

I've just found that my package.json doesn't have next dependency.
I've just added next on my package.json and it works.

VadimOnix added a commit to longway-llc/stock-journal that referenced this issue Jun 3, 2023
@diegorafael
Copy link

I ran into the exact same problem when I tried adding Docker after creating my app with npx create-next-app@latest. The version I had was 13.4.4 at the time. Unfortunately, 13.2.4 wasn't even an option because of some pesky compatibility issues.

My way to make things work was downgrading to version 13.4.0. Problem solved for now.

@hydRAnger
Copy link
Contributor

the same issue next@13.4.7 + output: 'standalone'

@damgel
Copy link

damgel commented Jun 27, 2023

same issue with #48077 and there is a workaround.

I confirm the same problem with this version as well. next@13.4.7

@carlosbaraza
Copy link

The problem persists in newer versions @ijjk. Could you reopen the ticket to track it? 13.4.0 works, 13.4.3 doesn't. Somewhere in that diff you can find the regression.

@viktordanov
Copy link

It appears next@13.4.8 doesn't suffer from the issue, can somebody else confirm this?

@benmkramer
Copy link

benmkramer commented Jul 5, 2023

It appears next@13.4.8 doesn't suffer from the issue, can somebody else confirm this?

I am also seeing this issue no longer occur on 13.4.8 in a test deployment this morning.

@diegorafael
Copy link

It appears next@13.4.8 doesn't suffer from the issue, can somebody else confirm this?

Same here. Just updated recently to 13.4.8 and that error apparently was fixed 😊

@emrecoban
Copy link

emrecoban commented Jul 7, 2023

I'm stuck. I'm working with r-suite package. This error occurs only on the imported r-suite page.

Error: Cannot find module '../../next@13.4.8_@babel+core@7.22.8_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/shared/lib/constants.js'
code: 'MODULE_NOT_FOUND',

next@13.4.8

Solved
This issue solved in next@13.4.9

@clarkedb
Copy link

The problem persists in newer versions @ijjk. Could you reopen the ticket to track it? 13.4.0 works, 13.4.3 doesn't. Somewhere in that diff you can find the regression.

There appears to be an even tighter window to find the regressions now because next@13.4.9 has the same error. As mentioned above next@13.4.8 works just fine, but the newest patch version next@13.4.9 yields the old error.

Error: Cannot find module 'next/dist/compiled/jest-worker'
Require stack:
- /app/node_modules/next/dist/server/lib/render-server-standalone.js
- /app/server.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/app/node_modules/next/dist/server/lib/render-server-standalone.js:12:21)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/app/node_modules/next/dist/server/lib/render-server-standalone.js',
    '/app/server.js'
  ]
}

@diegorafael
Copy link

diegorafael commented Jul 10, 2023 via email

@skd6150
Copy link

skd6150 commented Jul 11, 2023

It solved after install jest-worker manually

yarn add jest-worker --save-dev

@Clovel
Copy link

Clovel commented Jul 13, 2023

The problem persists in newer versions @ijjk. Could you reopen the ticket to track it? 13.4.0 works, 13.4.3 doesn't. Somewhere in that diff you can find the regression.

There appears to be an even tighter window to find the regressions now because next@13.4.9 has the same error. As mentioned above next@13.4.8 works just fine, but the newest patch version next@13.4.9 yields the old error.

I actually have the error using both ^13.4.8 and 13.4.8.

I am currently trying to dockerize my app using the following next.config.js :

const path = require('path');

module.exports = {
  reactStrictMode: true,
  output: 'standalone',
  transpilePackages: [
    'ui',
  ],
  eslint: {
    // Warning: This allows production builds to successfully complete even if
    // your project has ESLint errors.
    ignoreDuringBuilds: true,
  },
  // https://nextjs.org/docs/advanced-features/output-file-tracing#caveats
  experimental: {
    // this includes files from the monorepo base two directories up
    outputFileTracingRoot: path.join(__dirname, '../../'),
  },
};

I have tried commenting the experimental section to no avail.

I am using turbo@^1.10.7 and the turbo prune --scope=@monorepo/my-app --docker in the Dockerfile

EDIT : Typo in turbo prune command

@Clovel
Copy link

Clovel commented Jul 13, 2023

It solved after install jest-worker manually

yarn add jest-worker --save-dev

I tried this too, didn't work for me.

My config is available in the comment above, tried w/ 13.4.8, ^13.4.8, 13.4.9 & ^13.4.9 (I know some of these are equivalent, these tests are just to be thorough)

@ianldgs
Copy link
Contributor

ianldgs commented Jul 13, 2023

@Clovel out of curiosity:
do you see a warning about image optimization in the build output?

I'm pretty sure it says something if you don't have sharp installed.
Edit: yes, it does say

"Warning: For production Image Optimization with Next.js, the optional 'sharp' package is strongly recommended. Run 'yarn add sharp', and Next.js will use it automatically for Image Optimization."

There is an error at startup for me, even with sharp installed, but it works (even with 13.4.9)

"Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly. Read more at: https://nextjs.org/docs/messages/sharp-missing-in-production"

@Clovel
Copy link

Clovel commented Jul 13, 2023

@ianldgs nope, no warning about sharp. Here is my build output using yarn turbo run build --scope @monorepo/my-app :

cache miss, executing 2df99f8be5f4d3b5
$ next build
- info Creating an optimized production build...
- info Compiled successfully
- info Skipping linting
- info Checking validity of types...
- info Collecting page data...
- info Generating static pages (0/4)
- info Generating static pages (1/4)
- info Generating static pages (2/4)
- info Generating static pages (3/4)
- info Generating static pages (4/4)
- info Finalizing page optimization...

Route (app)                                Size     First Load JS
┌ ○ /                                      203 B          77.7 kB
├ ○ /client                                827 B           130 kB
└ λ /client/[clientId]                     815 B           130 kB
+ First Load JS shared by all              77.5 kB
  ├ chunks/7d8153d6-536594fdb27ed14b.js    50.5 kB
  ├ chunks/87-5ee5d3c272ad975f.js          25.1 kB
  ├ chunks/main-app-e82e76ea72f8ba20.js    215 B
  └ chunks/webpack-5e9bedb58c3695d7.js     1.71 kB

Route (pages)                              Size     First Load JS
─ ○ /404                                   182 B          75.5 kB
+ First Load JS shared by all              75.4 kB
  ├ chunks/framework-0857c1c24dbfb1d6.js   45 kB
  ├ chunks/main-1ee850a0b31c0d58.js        28.4 kB
  ├ chunks/pages/_app-64f57b430543ef5d.js  194 B
  └ chunks/webpack-5e9bedb58c3695d7.js     1.71 kB

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

Am I missing something ?

@ianldgs
Copy link
Contributor

ianldgs commented Jul 13, 2023

Am I missing something ?

No idea... my bet was sharp missing.
You do have it btw, right?
On the root package.json or on the app's package.json?
Regular deps or dev deps?

(Edit)
also interesting that you don't have:

- warn You have enabled experimental feature (outputFileTracingRoot) in next.config.js.

@ycalm
Copy link

ycalm commented Jul 24, 2023

It solved after install jest-worker manually

yarn add jest-worker --save-dev

I'm using next@13.4.9 and has the same issue, this work for me

@mickdewald
Copy link

mickdewald commented Jul 30, 2023

It solved after install jest-worker manually

yarn add jest-worker --save-dev

This helped me as well. But your command is not correct

Its
yarn add jest-worker --dev

--save-dev is for npm as far as I know

I am on "next": "^13.4.12"

@zoonun
Copy link

zoonun commented Aug 5, 2023

Downgrade next to 13.2.4 and it should work fine. It didn't work for me on 13.3.0. I've also tried downgrading sharp but to no avail.

This helped me.

I accounted an error when i used next@^13.4.12 + output: 'standalone'.
After downgrading to 13.2.4, it resolved. But it's a workaround...

@ReynardFox99
Copy link

It solved after install jest-worker manually

yarn add jest-worker --save-dev

worked for me. next@13.4.7 and node:18-alpine

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 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) bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.