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.
or
2 Replies
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:
or, if it's a local file:
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.Helpful Links:
npm: specifiers | Deno Docs
Types and Type Declarations | Deno Docs
dnt — the easiest way to publish a hybrid npm module for ESM and CommonJS
Overview of TypeScript in Deno | Deno Docs
Deno 1.26 Release Notes
deno.json configuration file | Deno Docs
Overview of TypeScript in Deno
Deno 1.34: deno compile supports npm packages
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.