Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow TypeScript files to be imported from npm packages #24093

Closed
kruncher opened this issue Jun 3, 2024 · 2 comments
Closed

Allow TypeScript files to be imported from npm packages #24093

kruncher opened this issue Jun 3, 2024 · 2 comments
Labels
duplicate a duplicate of another issue

Comments

@kruncher
Copy link

kruncher commented Jun 3, 2024

I am getting the following error when attempting to import a .ts file from an npm package (byonm):

TypeScript files are not supported in npm packages:

import { foo } from "some-node-module/abc.ts";
foo();

The source of the above error seems to be this: https://github.com/denoland/deno/blob/main/ext/node/resolution.rs#L454

There is a lot that I really like about deno but there are many scenarios where I want to be able to depend upon an entire package of files (scripts, stylesheets, templates, static assets, etc). There are many reasons where I find this to be useful; one such example is that of a reusable component library containing nunjucks templates and .scss files which can then be reused as a package across multiple services.

I would like to be able to reference a node module and then to import TypeScript files as-is and to be able to configure nunjucks to read templates from a directory structure from a package, and to be able to process .scss files where some are imported from a package.

In the node world npm packages quite easily allow for this and I think deno could potentially allow for this with its byonm feature. (As an aside I prefer to reference my own packages from GitHub repositories rather than publishing them to the npm registry).

@dsherret dsherret added the duplicate a duplicate of another issue label Jun 3, 2024
@dsherret
Copy link
Member

dsherret commented Jun 3, 2024

Took me a while to find, but duplicate of #16790

In the node world npm packages quite easily allow for this and I think deno could potentially allow for this with its byonm feature. (As an aside I prefer to reference my own packages from GitHub repositories rather than publishing them to the npm registry).

Node doesn't support TS files and so the Node compatibility layer aligns with Node.

I would like to be able to reference a node module and then to import TypeScript files as-is and to be able to configure nunjucks to read templates from a directory structure from a package, and to be able to process .scss files where some are imported from a package.

I believe you should be able to do this, minus the importing the TypeScript file as is. You should be able to import any js file in the package though.

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2024
@kruncher
Copy link
Author

kruncher commented Jun 3, 2024

@dsherret I can appreciate your thoughts on the linked issue regarding pollution of npm with TypeScript modules although I believe it is possible to import .ts modules from other packages given the right configuration.

Instead of using node_modules as a workaround I'd prefer to see some sort of equivalent in deno. Otherwise the irony is that people will end up building deno packages to npm just to be able to have packages when instead it would be cleaner to avoid that altogether by simply having the option to have deno packages.

eg. instead of node_modules being a first class citizen in deno, have deno packages (or even a generalised package mechanism) which deno is able to import typescript scripts from.

Please don't take this the wrong way, this isn't intended to be salty. I am expressing what I would personally like to be able to do with deno.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants