next.js: Error: Cannot find module 'next/dist/compiled/jest-worker' - On Docker

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

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 48
  • Comments: 43 (6 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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

@ijjk The README.md says

To add support for Docker to an existing project, just copy the Dockerfile into the root of the project and add the following to the next.config.js file:

I think this issue should not be closed until it is fixed for the latest version of nextjs or we should add a version hint to the README. Otherwise users will face this problem not just with existing apps > 13.2.4 but also with new created project through npx create-next-app@latest

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

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.

It solved after install jest-worker manually

yarn add jest-worker --save-dev

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

It solved after install jest-worker manually

yarn add jest-worker --save-dev

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

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.

same problem here, images don’t work in production after I upgraded next from 13.1.6 to 13.3.1

same issue 13.3.1-canary.4

That’s it so. Avoid odd version, guys 🤡

On Mon, 10 Jul 2023, 22:19 Clark Brown, @.***> wrote:

The problem persists in newer versions @ijjk https://github.com/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 @.*** has the same error. As mentioned above @.*** works just fine, but the newest patch version @.*** 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’ ] }

— Reply to this email directly, view it on GitHub https://github.com/vercel/next.js/issues/48173#issuecomment-1629746394, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLJAO4DXEFESF4KHI5FTYDXPRWVXANCNFSM6AAAAAAWYLG7BE . You are receiving this because you commented.Message ID: <vercel/next. @.***>

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

same issue with #48077 and there is a workaround.

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