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

Favicon not found with file-based metadata in standalone build #48962

Closed
1 task done
BigOoga opened this issue Apr 28, 2023 · 7 comments · Fixed by #49208
Closed
1 task done

Favicon not found with file-based metadata in standalone build #48962

BigOoga opened this issue Apr 28, 2023 · 7 comments · Fixed by #49208
Assignees
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. Metadata Related to Next.js' Metadata API. Output (export/standalone) Related to the the output option in `next.config.js`.

Comments

@BigOoga
Copy link

BigOoga commented Apr 28, 2023

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: #67-Ubuntu SMP Mon Mar 13 14:22:10 UTC 2023
    Binaries:
      Node: 16.19.0
      npm: 8.19.3
      Yarn: 1.22.19
      pnpm: 7.21.0
    Relevant packages:
      next: 13.3.1-canary.18
      eslint-config-next: 13.3.1
      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), Metadata (metadata, generateMetadata, next/head, head.js), Standalone mode (output: "standalone")

Link to the code that reproduces this issue

https://github.com/BigOoga/standalone-metadata-bug

To Reproduce

Run docker-compose up --build to build the image and run the container

Describe the Bug

Going by the error
Error: ENOENT: no such file or directory, open '/app/src/app/favicon.ico'
The server tries to open the image path as if running the server with next start.

Expected Behavior

I'd expect the standalone build to correctly bundle the favicon and correctly path to it.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

dockerized standalone build

@BigOoga BigOoga added the bug Issue was opened via the bug report template. label Apr 28, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Metadata Related to Next.js' Metadata API. Output (export/standalone) Related to the the output option in `next.config.js`. labels Apr 28, 2023
@masterkain
Copy link

same issue

@sFritsch09
Copy link

#49107

@sidmclaughlin
Copy link

As of Next.js 13.3.4, the standalone output doesn't properly copy the favicon, and instead expects it to be present at the same path as during the build phase.

A quick workaround is to add a COPY to your runner phase, mimicking the same path as provided in the error.

COPY --from=builder --chown=nextjs:nodejs /app/src/app/favicon.ico ./src/app/favicon.ico

Brief discussion: #41745 (comment)
Repro w. fix: https://github.com/sidmclaughlin/nextjs-favicon-repro (see Dockerfile-broken, Dockerfile-fixed)

@huozhi huozhi self-assigned this May 3, 2023
@sFritsch09
Copy link

sFritsch09 commented May 4, 2023

My working Dockerfile 🐳:

# dependencies image
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# build image
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN yarn build

# build output image
FROM node:20-alpine AS run
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
WORKDIR /app
COPY --from=builder --chown=nextjs:nodejs /app/package.json /app/yarn.lock ./
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/app/favicon.ico ./app/favicon.ico
COPY --from=builder --chown=nextjs:nodejs /app/app/icon.png ./app/icon.png
COPY --from=builder --chown=nextjs:nodejs /app/app/opengraph-image.jpg ./app/opengraph-image.jpg
COPY --from=builder /app/next.config.js ./next.config.js
USER nextjs
EXPOSE 3000
CMD [ "yarn", "start" ]

feedthejim pushed a commit that referenced this issue May 4, 2023
Fixes #48962
Fixes #49009
Fixes #49107 

### Why

For standalone mode the `fs.readFile` is executed for `route.js` when
the module is loaded, then the fs operation aginst the wrong file path
will break the proper module loading, then it fallbacks to `/_error`
module.

### What

We move the fs read operation to the first get then cache the buffer in
the module level variable, so that `fs.readFile` won't be executed. As
we already have prerender cache, the meta/body fs cache will be HIT and
served
@huozhi
Copy link
Member

huozhi commented May 4, 2023

We got a fix out in 13.4, upgrade it to check it out if resolves the issue 🙏

@BigOoga
Copy link
Author

BigOoga commented May 5, 2023

We got a fix out in 13.4, upgrade it to check it out if resolves the issue pray

I updated and it's now working perfectly on my setup, thank you!

@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2023

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 Jun 4, 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. Metadata Related to Next.js' Metadata API. Output (export/standalone) Related to the the output option in `next.config.js`.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants