Skip to content

TimoGlastra/tsdown-dynamic-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic import not converted

Source code is written as:

export async function run() {
  const myLib = await import("some-lib");
}

run();

However output for CJS is:

//#region src/index.ts
async function run() {
  await import("some-lib");
}
run();

//#endregion
exports.run = run;

I would expect the dynamic import to be rewritten as a dynamic require:

//#region src/index.ts
async function run() {
  require("some-lib");
}
run();

//#endregion
exports.run = run;

I was able to work around it in a hacky way by adding a plugin, but this doesn't feel like the way to resolve this.

plugins: [
  {
    name: "import-require",
    transform: (code) => {
      return code.replaceAll(" await import(", " require(");
    },
  },
];

Reproduce

The dist folder is included. But you can run yarn install (optionally corepack enable) and then yarn tsdown

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors