Tips and Error Solutions

Error: Cannot find module with dynamic import

Allen Kim

--

https://github.com/webpack/webpack/issues/6680#issuecomment-370800037

Webpack performs a static analyse at build time. It doesn’t try to infer variables

Don’t do

const path = `./${name}.component`;
const imported: any = await import(path);

Do instead

const imported: any = await import(`./${name}.component`);

If you want component name as a variable

const imported: any = await import(`./${name}.component`);
const komponent = imported[`MyComponent`];
const btnCompFactory = this.cfr.resolveComponentFactory(komponent);

--

--