Next build doesnt work with png imports
See original GitHub issueWhat 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:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top 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 >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 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!!I would recommend trying out the built-in Next.js image handling and removing
next-images
if you can.