Skip to content
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

Compiled Deno project can't import typescript code #27945

Open
localhosted opened this issue Feb 3, 2025 · 1 comment
Open

Compiled Deno project can't import typescript code #27945

localhosted opened this issue Feb 3, 2025 · 1 comment
Labels
compile related to the `deno compile` feature

Comments

@localhosted
Copy link

It's currently not possible to import Typescript code after compilation.

I'd like to be able to compile code for easier deploy, without losing Deno capabilities

async function importjs(js: string, filename = "importedjs") {
  const dataUri =
    "data:text/typescript;charset=utf-8," +
    encodeURIComponent(js) +
    `//# sourceURL=${filename}.ts;`;
  const r = await import(dataUri);
  return r;
}

console.log(
  (await importjs(`export default () => "hello world" as any`)).default()
);
@dsherret dsherret added suggestion suggestions for new features (yet to be agreed) compile related to the `deno compile` feature labels Feb 3, 2025
@dsherret
Copy link
Member

dsherret commented Feb 3, 2025

We don't include a TypeScript parser and transpiler in the compiled executable in order to save a lot of space for people who don't use it (I think 5MB IIRC). Probably in the future this use case would be solved via custom loaders and being able to include your own transpiler.

Related: #18327

@dsherret dsherret removed the suggestion suggestions for new features (yet to be agreed) label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compile related to the `deno compile` feature
Projects
None yet
Development

No branches or pull requests

2 participants