TS1323

Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.

Broken Code โŒ

main.ts
import('trading-signals').then((tradingSignals) => {
  const { Big, SMA } = tradingSignals;
 
  const sma = new SMA(3);
});
tsconfig.json
{
  "compilerOptions": {
    "module": "es2015"
  }
}

Fixed Code โœ”๏ธ

Dynamic imports are expressions that enable the loading of an ECMAScript module (ESM) into CommonJS modules (CJS).

The import() expression also allow modules to be loaded conditionally on demand. This feature was introduced with the ECMAScriptยฎ 2020 Language Specification.

If your project uses an older module system, remember to update the module setting in your TypeScript compiler settings.

main.ts
import('trading-signals').then((tradingSignals) => {
  const { Big, SMA } = tradingSignals;
 
  const sma = new SMA(3);
});
tsconfig.json
{
  "compilerOptions": {
    "module": "node16"
  }
}