localhost
localhost3w ago

Compiled Deno project can't import typescript code

Does Deno compile remove its ability to import typescript code? This only work in deno run, but fails on the deno compile bynary
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()
);
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()
);
4 Replies
marvinh.
marvinh.3w ago
Yes, the compiled artifact is a slimmed down version of deno with non-critical stuff like the test runner, transpiler etc removed
localhost
localhostOP3w ago
would it be possible to have flags on how slim you want the copmiled binary to be? Is it feasible for a non-Rust expert to fork and maintain?
marvinh.
marvinh.3w ago
at the moment no. I don't think there are plans to add this either would love an issue on github for this though which outlines the use cases. I think right now there is nothing that tracks that
localhost
localhostOP3w ago
opened #27945

Did you find this page helpful?