cyrilwanner / next-optimized-images

🌅 next-optimized-images automatically optimizes images used in next.js projects (jpeg, png, svg, webp and gif).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Type error: Cannot find module '*.png' or its corresponding type declarations" when updating to next v.11.1.0

sakerhetspolisen opened this issue · comments

After updating the next package to v.11.1.0 and running next build I get the following error:

Type error: Cannot find module '../public/images/socialImage.png' or its corresponding type declarations.

10 \| // Custom
11 \| import "../styles/global.css";
12 \| import socialImage from "../public/images/socialImage.png";

It seemed like the package was interfering with static image imports in the application, so I added the following in the next.config.js file (following this solution):

const withOptimizedImages = require('next-optimized-images');
 
module.exports = withOptimizedImages({
  /* config for next-optimized-images */
  images: {
    disableStaticImages: true,
    ...
  },
...

, but this didn't resolve my problem. Instead, since I realized that Next introduced Image Optimization in v.10, I removed the next-optimized-images package and the import in the next.config.js file. Now it works.