RogueMan
RogueMan4w ago

Executable having trouble with types

I'm encountering a syntax error when trying to import files when running an executable, specifically with type imports. I have included the entire ./src/modules/test directory into the binary When running a compiled binary, I'm getting a SyntaxError related to type imports. Here's the specific code causing issues: path: ./src/modules/test/commands/testing.ts
import { type Config } from '@types';

const config = {} as Config;
console.log('Hello, world!');
import { type Config } from '@types';

const config = {} as Config;
console.log('Hello, world!');
Function used to import files:
this is the code that imports the files:
/**
* Dynamically import all files matching the glob pattern
* @param globPath - The glob pattern to match files
*/
export async function importer(globPath: string) {
if (Deno.args.includes('--is_compiled_binary')) {
// Import the manifest file and import all files listed in it
const { default: manifest } = await import(import.meta.resolve('../../../manifest.json'));

for (const module of manifest.modules) {
for await (const commandFiles of Deno.readDir(${join(import.meta.dirname!, '../../../')}${module}/commands)) {
await import(import.meta.resolve(`file:///${join(import.meta.dirname!, '../../../')}${module}\\commands\\${commandFiles.name}\));
}
}
}
}
this is the code that imports the files:
/**
* Dynamically import all files matching the glob pattern
* @param globPath - The glob pattern to match files
*/
export async function importer(globPath: string) {
if (Deno.args.includes('--is_compiled_binary')) {
// Import the manifest file and import all files listed in it
const { default: manifest } = await import(import.meta.resolve('../../../manifest.json'));

for (const module of manifest.modules) {
for await (const commandFiles of Deno.readDir(${join(import.meta.dirname!, '../../../')}${module}/commands)) {
await import(import.meta.resolve(`file:///${join(import.meta.dirname!, '../../../')}${module}\\commands\\${commandFiles.name}\));
}
}
}
}
Full Error Message:
SyntaxError: Unexpected identifier 'Config' at file:///C:/Users/renor/AppData/Local/Temp/deno-compile-bot.exe/deno-discord-bot-template/src/modules/testing/commands/testing.ts:1:15
at async importer (file:///C:/Users/renor/AppData/Local/Temp/deno-compile-bot.exe/deno-discord-bot-template/src/utils/functions/files.ts:12:52)
at async Function.main (file:///C:/Users/renor/AppData/Local/Temp/deno-compile-bot.exe/deno-discord-bot-template/src/main.ts:55:7) {
code: "ERR_MODULE_NOT_FOUND"
}
SyntaxError: Unexpected identifier 'Config' at file:///C:/Users/renor/AppData/Local/Temp/deno-compile-bot.exe/deno-discord-bot-template/src/modules/testing/commands/testing.ts:1:15
at async importer (file:///C:/Users/renor/AppData/Local/Temp/deno-compile-bot.exe/deno-discord-bot-template/src/utils/functions/files.ts:12:52)
at async Function.main (file:///C:/Users/renor/AppData/Local/Temp/deno-compile-bot.exe/deno-discord-bot-template/src/main.ts:55:7) {
code: "ERR_MODULE_NOT_FOUND"
}
Deno Version: 2.1.2
9 Replies
RogueMan
RogueManOP4w ago
Is this a known issue with type imports during compilation? Are there any recommended workarounds for type imports in compiled Deno executables? Any insights or help would be greatly appreciated! 🙏
Leokuma
Leokuma3w ago
What is @types? Is it declared in an import map?
RogueMan
RogueManOP3w ago
Yes it is
Leokuma
Leokuma3w ago
Are you passing the import map to the deno compile command?
RogueMan
RogueManOP3w ago
yes, the import mapping doesnt seem to be the issue. Everything runs just fine when using deno run. It only seems to happen when running a compiled binary @bartlomieju Sorry for pinging you, but you really helped me last time. I was wondering if you had any idea how I can fix this. Been stuck on this for a few days and can't seem to find anything online.
Kitura
Kitura3w ago
Have you tried importing the types using @deno-types? https://docs.deno.com/runtime/fundamentals/node/#importing-types
Deno
Node and npm support
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
RogueMan
RogueManOP3w ago
it's a custom type 😄
bartlomieju
bartlomieju3w ago
I think this is a bug in deno compile, it might not be including all necessary files, or something goes wrong when you have import type .... Could you please open an issue for it with a full repro?
RogueMan
RogueManOP3w ago
Opened an issue

Did you find this page helpful?