TS2307: Cannot find module ‘./images/logo.png’

I found the answer here. Webpack & Typescript image import

Here’s what I did.

Added a new directory and a import-png.d.ts file

root
-typings
--custom
---import-png.d.ts

import-png.d.ts

declare module "*.png" {
  const value: any;
  export default value;
}

changed my file-loader module to this:

{
      test: /\.(png|jpe?g|gif|jp2|webp)$/,
      loader: 'file-loader',
      options: {
        name: 'images/[name].[ext]'
      }

and now I can import with a statement like this:

import Logo from './images/logo.png'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)