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.

Next build doesnt work with png imports

See original GitHub issue

What version of Next.js are you using?

11.1.2

What version of Node.js are you using?

14.17.3

What browser are you using?

Chrome

What operating system are you using?

Ubuntu

How are you deploying your application?

next build

Describe the Bug

While developing, an error appeared in an image import. However, the image rendered normally and appeared on the screen. However, when giving build, for some reason the script does not go through this step.

Following error:

yarn run v1.22.5
$ next build
info  - Loaded env from /media/XXX/ubuntuHD/workspace/XXX/landing/.env
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
Failed to compile.

./src/pages/index.tsx:8:24
Type error: Cannot find module '../assets/cards.png' or its corresponding type declarations.

   6 | 
   7 | //assets
>  8 | import cardsImage from "../assets/cards.png"
     |                        ^
   9 | import logo from "../assets/logo192.png"
  10 | 
  11 | export default function Home() {
error Command failed with exit code 1.

Expected Behavior

Script build normally

To Reproduce

Just run yarn run build with a png import

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lucasReghiniMcommented, Sep 22, 2021

i already removed the next-images to solve that build problem. Now I will try what you said. Because I want to import the images directly from src Thanks a lot for the quick answer!!

1reaction
ijjkcommented, Sep 22, 2021

I would recommend trying out the built-in Next.js image handling and removing next-images if you can.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't import static files like images · Issue #1935 · vercel/next.js
it comes the error: This module was not found: * /static/enen.png in ./pages?entry To install it, you can run: npm install --save /static/enen....
Read more >
I can't reference an image in Next.js - Stack Overflow
import Image from "next/image" <Image src="/sample-image.png" ... it worked for me like this, but putting the file in the public folder:
Read more >
next/image - Next.js
The default behavior allows you to import static files such as import icon from './icon.png and then pass that to the src property....
Read more >
How to import image in Next.js ? - GeeksforGeeks
In this article, we will learn to import images in Next.js using the ... The Image component supports the following built-in optimizations:.
Read more >
next-images - npm
TypeScript icon, indicating that this package has built-in type ... Import images in Next.js (jpg, jpeg, png, svg, fig, ico, webp, ...
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