-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Deno unexpected token error when importing TypeScript in node_modules with Next.js #27782
Comments
TypeScript isn't supported in Node in npm packages, even with the new typescript mode and so it hasn't been supported in Deno for this same reason. The library authors will need to transpile their TypeScript to JavaScript if they wish to be Node and thus Deno compatible. |
For reference:
|
Oh, I see now. For the sake of clarity, does this show that you tried doing the same thing with Node, even with experimental ts support enabled, and it didn't work? |
@dmint789 yes, exactly. |
Oh, I see. Thanks a lot! I should've thought to try that myself. |
If this is the permanent stance of Other bundlers and runtimes have no issue running TypeScript code packages with very sensible semantics and performance. I absolutely understand that some of them do not, but they do not brand themselves as having "Native TypeScript support" and "TypeScript without the hassle" on their front page. We published this particular entry point as TypeScript because I absolutely respect |
I'm not an expert on builders, bundlers, JS/TS runtimes, etc., but I also think this would be nice to have. Deno has made my life easier on many fronts, but I also wish it supported pure TS modules (besides JSR). |
Sorry, I just realized this was for specifically in the editor for bundlers and not at runtime.
Please be a little more graceful when writing comments on issues. |
I'm not sure what you mean. I don't get any errors in the editor, it only happens at runtime (or bundle time? It's a Next JS project, so there's a webpack build step involved). Actually, that made me realize that the title of this issue is incorrect then. So is the issue not Deno, but rather Webpack then? |
If the code in the npm package is meant for runtime, then the library should be distributing the code as JS with targeted DTS files. This restriction exists in both Node and Deno for the ecosystem benefits it brings because npm packages are not designed to ship TypeScript files performantly. The TypeScript team also heavily discourages the practice. That said, it's sounding like the bundler isn't correctly bundling the code here for some reason and it wouldn't work in node at runtime either so I'm not sure it's a bug. |
@dmint789 are you able to create a reproduction with next.js somewhere? |
My apologies, I could have worded that with more empathy. I hope you can forgive my tone of my post if you have a chance to take into account its content some day. |
That is very passive-aggressive... @dsherret I'll make a reproducible example. |
Ok, so this isn't a deno bug. The error comes from Next.js. I'm able to reproduce with I'm not sure the exact way to fix it, but it looks like there's an issue here: vercel/next.js#74252 |
I see. Thanks a lot for investigating this! |
Version: Deno 2.1.7
I'm having an issue with one of my NPM dependencies that has an export like this:
I'm getting the following error when importing any of these exports in my Next JS project:
When I directly remove the parts with export type in the NPM package, that error goes away, but then I get an error with export enum CubingIcons. Afaik, export type and export enum are both regular Typescript features, so I would like to be able to use this module in my project. In fact, I have plenty of my own files with export type/interface/enum, and Deno handles them just fine when they're not inside of an NPM package.
The text was updated successfully, but these errors were encountered: