Skip to content

[BUG] ImageComponent does not work when combine trailingSlash and basePath #36681

@raulfdm

Description

@raulfdm

Verify canary release

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

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.14.2
      npm: 7.24.2
      Yarn: 1.22.17
      pnpm: 6.27.1
    Relevant packages:
      next: 12.1.7-canary.1
      react: 17.0.2
      react-dom: 17.0.2

What browser are you using? (if relevant)

Microsoft Edge Version 101.0.1210.32 (Official build) (arm64)

How are you deploying your application? (if relevant)

next start

Describe the Bug

When we combine basePath with trailingSlash, the next/image component does not applies the correct src and srcSet.

It always generates /_next/... instead /<base-path>/_next/....

That leads to images not loading properly.

Expected Behavior

Add the basePath into the generated src and srcSets so the image can be loaded properly.

To Reproduce

  1. clone this project: https://github.com/raulfdm/next-basepath-trailing-image-bug
  2. install the dependencies npm install
  3. run the server npm run dev
  4. open the app at http://localhost:3001/docs/
  5. see the image component failing
  6. press the button that adds the base path
  7. the image should be properly displayed

If you run npm build && npm start, the image will still be broken.

Metadata

Metadata

Assignees

Labels

Image (next/image)Related to Next.js Image Optimization.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions