-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Files Not Automatically Converted to ECMAScript Modules (.mjs) #350
Comments
Can you please make a runnable reproduction so I can test? 🙏🏼 |
I replied to this Issue but then deleted the reply to have a better understanding. After so much playing around, I reached the conclusion that this Issue matches mine. unbuild is failing to add the .mjs extension to the source code of the built files for dynamic imports without extension In my case I'm building a My drastic workaround was, instead of loading the templates Any info will be highly appreciated. 🔥💚🤝😊 |
Both // ./utils/one.ts
export const one = 1
// index.ts
export async function getOne() {
return await import(`./utils/one.ts`).then(m => m.one)
} After compiling: // index.mjs
async function getOne() {
return await import('./chunks/one.mjs').then((m) => m.one);
}
export { getOne }; I think the problem is that it seems unbuild do not support dynamic import with variables, which is a feature of Vite: const module = await import(`./dir/${file}.ts`) To confirm that, use the code below: // index.ts
export async function getOne() {
const path = 'one'
return await import(`./utils/${path}.ts`).then(m => m.one)
} After compiling: // index.mjs
async function getOne() {
const path = "one";
return await import(`./utils/${path}.ts`).then((m) => m.one);
}
export { getOne }; |
When importing a TypeScript file using the .ts extension, the build process does not automatically convert it to an ECMAScript module with the .mjs extension. This leads to import errors, as the expected file format is not found.
After import build there is a problem because .ts does not convert to mjs. How can I do this
The text was updated successfully, but these errors were encountered: