numberkruncher
numberkruncher7mo ago

error: TypeScript files are not supported in npm packages:

I am wondering why I cannot import a .ts file from a node_modules directory. If I could do this then I could use npm as a package manager which would allow me to take advantage of the things that I love about deno as well as being able to work with modules in a familiar way (eg. bundle templates, stylesheets, static assets, whatnot alongside the scripts). eg.
import { foo } from "./node_modules/abc/main.ts";
foo();
import { foo } from "./node_modules/abc/main.ts";
foo();
or
import { foo } from "@abc/main.ts";
foo();
import { foo } from "@abc/main.ts";
foo();
2 Replies
Deno AI Helper
Deno AI Helper7mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, it's important to note that Deno is designed to use ES modules and does not support the node_modules system that is common in Node.js. Deno also encourages the use of URLs for module imports rather than local paths like node_modules. In Deno, TypeScript files can be imported directly via URLs, and Deno will handle the compilation for you. The error message you're encountering suggests that you're trying to import TypeScript files from a node_modules directory, which is not the standard practice in Deno. If you're trying to import a TypeScript file in Deno, you would typically do so from a URL or a local path that does not involve node_modules. For example:
import { foo } from "https://example.com/abc/main.ts";
foo();
import { foo } from "https://example.com/abc/main.ts";
foo();
or, if it's a local file:
import { foo } from "./path/to/your/modules/main.ts";
foo();
import { foo } from "./path/to/your/modules/main.ts";
foo();
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. If you're looking to use npm packages within Deno, you might need to look into tools that convert npm packages to Deno-compatible ES modules or explore other ways to include the functionality you need within the Deno ecosystem.
phoenisx
phoenisx4mo ago
I guess this is an issue with latest deno canary and vscode extension. I was using deno 2.0 rc, and when downgraded to deno 1.46.3 the extension didn't report any errors. Naah! Something weird is happening. I tried to control click the import and it start showing an error again.

Did you find this page helpful?