Ts-Loader Won't Allow Dynamic Module Imports

44 views Asked by At

I am trying to compile a simple index.ts file using webpack's ts-loader; the file uses dynamic imports. In my webpack.config.js I have my alias set to: Images: `path.resolve(__dirname, './src/images'), and my tsconfig.json has "baseUrl": "./src", "paths": { "Images/*": ["images/*"]} . Both of these should work fine in resolving the import path for this function:

function sampleComponent() {
  return import('Images/cow.jpg')
    .then(({ default: cowImg }) => {
      const img = new Image(400, 400);
      img.src = cowImg;
      img.classList.add('test-style');
      return img; 
    })  
    .catch(e => console.error(e));
}

When I try to compile, I get the error: Cannot find module Images/cow.jpg or its corresponding type declarations.ts(2307) .

0

There are 0 answers