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

[with-docker] COPY failed: stat app/.next/standalone: file does not exist #38686

Closed
1 task done
RobertoDonPedro opened this issue Jul 15, 2022 · 5 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@RobertoDonPedro
Copy link

Verify canary release

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

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #18~20.04.1-Ubuntu SMP Sun Jul 3 08:20:07 UTC 2022
Binaries:
  Node: 16.16.0
  npm: 8.11.0
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.0.10
  react: 17.0.2
  react-dom: 17.0.2

Which example does this report relate to?

with-docker

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

I am running sudo docker build -t myapp . (on a GCP VM) and I get this error below:

Step 21/26 : COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY failed: stat app/.next/standalone: file does not exist

Note: I've done all required step for existing projects as described here.

Expected Behavior

Build the image without error

To Reproduce

  • Copy Dockerfile in the base directory of your app
  • Update next.config.js like so:
// next.config.js
module.exports = {
  // ... rest of the configuration.
  output: 'standalone',
}
  • Run sudo docker build -t myapp .
@RobertoDonPedro RobertoDonPedro added the bug Issue was opened via the bug report template. label Jul 15, 2022
@RobertoDonPedro
Copy link
Author

Note: If I remove the line COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ from the Dockerfile it builds the image.

But then when I try to run it with sudo docker run -p 3000:3000 myapp I get this error

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module '/app/server.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

@balazsorban44
Copy link
Member

balazsorban44 commented Jul 15, 2022

This is because you are on an older version of Next.js (12.0.10) that did not use output: "standalone" but experimental: {outputStandalone: true}. You should upgrade next@latest and it should work. (Note that experimental features are not covered by semver. Relevant PR #37994)

@RobertoDonPedro
Copy link
Author

Thanks for the quick response. I've updated to Next.js 12.2.2 and now it works as supposed.

@ivankovnatsky
Copy link

Sorry to ping you here, I'm trying to use standalone with "next": "^12.0.3-canary.7",:

const standaloneConfig = {
  experimental: {
    outputStandalone: true,
  },
}

module.exports = withPlugins(standaloneConfig)

And seeing same error, not sure how to check if this version supports it, can you please confirm that it does support it? Thanks a lot.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. 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 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants