next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Next/Image is not getting copied in static media

Open ad-manish opened this issue 2 years ago • 2 comments

Link to the code that reproduces this issue

https://github.com/algodomain/nextjs-image-issue

To Reproduce

Use the public folder and copy any image under img folder

root
|_ public
       |_ img
             |_ test-img.png

inside your component

<Image src="/img/test-img.png" alt="Image" width="900" height="600" />

When I run the build, it creates a folder as .next/static/media but test-img.png (or test-img.[random_num].png file is missing npm run build

So that you know, these files are being copied if we refer to the image via CSS file, which is strange behaviour.

// notice ../ before the url

Also note that if you use inline css via your nextjs server component, the image is again missing

style={{ backgroundImage: 'url(/img/test-img.png)' }}
//or
style={{ backgroundImage: 'url(../img/test-img.png)' }}

However, when I deploy the public folder in my server, these images are getting served, therefore I believe this is indeed a bug and must be fixed, why images are not being copied when we are using <Image> component of nextjs.

Current vs. Expected behavior

Image must be copied inside .next/static/media directory which is not the case when using <Image> but being copied when referenced from css file (added in rootLayout) (but not inline css)

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.21
  pnpm: N/A
Relevant Packages:
  next: 14.0.4
  eslint-config-next: 14.0.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

App Router, Image optimization (next/image, next/legacy/image)

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

ad-manish avatar Jan 03 '24 10:01 ad-manish

@GhidorahRex PLEASE will/can you advise if this is okay (and correct) to still merge and hasn't been outdated by any subsequent changes that have been made? (or other similar PRs fixing issues with ARM instructions)

f-raZ0R avatar Dec 17 '24 15:12 f-raZ0R

This looks good. I'll try to get it pulled in soon.

GhidorahRex avatar Dec 19 '24 11:12 GhidorahRex