question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing image doesn't work with basePath

See original GitHub issue

What 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

  1. Create a new next application
  2. Configure basePath in next.config.js
  3. Import image like in “Describe the Bug” step
  4. Try to
    1. console.log imported object
    2. use it in Image or img component

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Bielik20commented, Sep 29, 2021

I have tested today with 11.1.3-canary.35 and it works great. Thank you for handling this 🙇

0reactions
balazsorban44commented, Jan 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found