kin.ts
kin.ts•10mo ago

Cannot find module

I tried importing '../api/index.js' but got the error 'module not found', I knew this error would appear, I'm not sure how to import this module (I forked the module from discord.js), so, is there a way to import the ts file as a js file?
4 Replies
kin.ts
kin.ts•10mo ago
@Deno AI Helper
Deno AI Helper
Deno AI Helper•10mo ago
Sure, I'd be happy to help. Could you please provide me with the question you'd like me to answer?
kin.ts
kin.ts•10mo ago
I tried importing '../api/index.js' but got the error 'module not found', I knew this error would appear, I'm not sure how to import this module (I forked the module from discord.js), so, is there a way to import the ts file as a js file?
Deno AI Helper
Deno AI Helper•10mo ago
Based on the documentation, Deno supports importing both JavaScript and TypeScript files. However, it's important to note that Deno uses browser-like module resolution, meaning that file names must be specified in full. You may not omit the file extension and there is no special handling of index.js. If you're trying to import a TypeScript file as a JavaScript file, you might encounter issues because TypeScript and JavaScript have different syntax. TypeScript includes type annotations and other features that aren't valid JavaScript. Deno can handle TypeScript files because it has a built-in TypeScript compiler. If you're trying to import a TypeScript file, you should use the .ts extension in your import statement. For example:
import module from "../api/index.ts";
import module from "../api/index.ts";
If you're trying to import a JavaScript file that doesn't exist, you'll need to ensure the file is in the correct location and that you're using the correct path in your import statement. If you're working with a module that you've forked from another project (like discord.js), you might need to build the TypeScript source files into JavaScript if the JavaScript files aren't included in the project. This typically involves running a command like tsc (the TypeScript compiler) to compile the TypeScript code into JavaScript. Remember, when importing modules in Deno, the paths to modules can be URLs or file system paths. If the module is not in the Deno standard library or isn't a built-in module, you'll need to include the full URL or path to the module in your import statement. If you're still having trouble, could you provide more details about the structure of your project and the exact import statement you're using? That might help identify the issue. 🦕