Importing image doesn't work with basePath
See original GitHub issueWhat version of Next.js are you using?
v11.1.2
What version of Node.js are you using?
v14.16.1
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Other platform
Describe the Bug
When importing image (feature introduced in Next 11) like:
import error404Image from './assets/error-404.png';
src
field on imported object doesn’t take into account basePath
.
So the src
to image will be: http://localhost:4202/_next/static/image/...
Expected Behavior
src
to image should be: http://localhost:4202/${basePath}/_next/static/image
Previously used https://www.npmjs.com/package/next-images handled that correctly.
To Reproduce
- Create a new next application
- Configure
basePath
innext.config.js
- Import image like in “Describe the Bug” step
- Try to
console.log
imported object- use it in
Image
orimg
component
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
NextJS v10 Image component fails to serve image when there ...
Meanwhile, as a workaround, (from the linked issue) import React from 'react'; import Image from 'next/image'; const basePath = process.env.
Read more >How to change the base path in nextjs? - Medium
In nextjs your images in the asset folder, you cannot access an image with a base path. You import images and use them....
Read more >Documentation - Module Resolution - TypeScript
If you are having resolution problems with import s and export s in TypeScript, try setting moduleResolution: "node" to see if it fixes...
Read more >Advanced Features: Absolute Imports and Module Path Aliases
Configure module path aliases that allow you to remap certain import paths. ... While baseUrl is useful you might want to add other...
Read more >URL in media file path - Help
In my recent import from WikiTree there were almost 300 images. ... The problem may be that the website is preventing the download....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have tested today with
11.1.3-canary.35
and it works great. Thank you for handling this 🙇This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.