-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
export not found when executing typescript file #7384
Comments
I'm seeing this too. I have this import inside the the file where the error is occurring but bun doesn't recognize it..
|
+1
|
TypeScript types don't exist at runtime, so importing them doesn't work. When you want to import types from files, you must tell Bun that it is a TypeScript type and not a file: import {type OpenAIModelName} from '...' Instead of import {OpenAIModelName} from '...' Or you can do import type {OpenAIModelName} from '...'` Please set I'm closing this as "Not planned" because the fix is to specify Please leave a comment if that explanation isn't enough to help you fix this |
Thanks for the solution! Today, I also found an alternative for those using eslint & don't want to enable Adding this into the config & using {
"rules": {
"@typescript-eslint/consistent-type-imports": "error",
}
} Requires typescript-eslint stuff to work. |
This does make it much harder to migrate an existing project to bun. We have to try and go through each of the thousands of files in our project and add the |
vscode automatically adds imports without adding the |
Well, I went the nuclear option and ran Edit: Only that didn't actually work because the eslint rule is too strict. We're using NestJS and now nest doesn't recognize the types that are being injected due to the type modifier that the eslint rule automatically added... 🤦 I need a tool that's a bit smarter than this eslint rule that actually evaluates the type original type that's being imported to tell if it's type or interface and then adds the modifier... Edit 2: I found that if you run eslint with type-aware linting it will ignore instance of types used in decorators and constructors, which gets me a lot closer to where I can run the application, but not quite. There are still quite a few places I need to manually add the type modifier, but it's a little more manageable. Also, for vscode/typescript 5.3 there is an option to prefer type imports: |
This issue is definitely hurting adoption in our company for backend projects. The expectation is typically that if project was previously ran through ts-node in development, it should be able to run after replacing it with It kinda looks like even though bun is saying that is it supports Typescript, it more like it supports just a subset of it, and that using ESLint is mandatory to ensure that there are no runtime errors when using unsupported features. In my opinion, if issues like this are closed as "not planned", the project documentation should mention that it will never suport all features, and should recommend a specific ESLint configuration to not accidentally run into runtime errors with perfectly valid Typescript code. |
I had the same problem with bun test concerning types. When bun runs the tests, it is in an already compiled environment, so it doesn't logically find the types. For me, the solution was to specify not only when importing but also when exporting types. Example:
I didn't need to configure ESLint. In fact, on this project I was using biome. On the contrary, I think it's a good thing to have to type imports/exports properly. |
I'm mainly interested in getting this merged to eventually run `damage-calc` under bun (they apparently don't support importing types without doing this oven-sh/bun#7384 (comment)) The changes are mostly generated with the new eslint rule + `eslint --fix .` (with some manual fixes after) https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
Running the tests in Jest works, running bun test is emitting errors like this: I think for significant projects (ones closing on 1m+ lines, thousands of files/tests), this is practically unfixable. A better error message would make a transition more achievable, specifically the file where the import is failing. Any context at all would be an improvement. Alternatively bun compatibility with jest would help, though we'd just as soon fix these sorts of issues. |
We are going to fix this. It will involve changes to JavaScriptCore (the engine) to better support TypeScript. Here's roughly how we're planning to fix it: Step 1
This first step does two things: a) Remove redundant parsing step, improving ESM performance a little bit. Step 2
|
What version of Bun is running?
1.0.14+d8be3e51b
What platform is your computer?
Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 unknown
What steps can reproduce the bug?
git clone https://github.com/MRDGH2821/Discord-Ban-Utils-Bot
inside WSL.rewrite-sapphire
branchbun src/index.ts
What is the expected behavior?
Code should run successfully
What do you see instead?
EventTypes.ts
is located insrc/lib
And
ValueOf
is defined insrc/lib/EventTypes.ts
, re-exported insrc/lib/utils.ts
Additional information
My bot requires the following to start:
And, I'm using Dev container inside WSL
The text was updated successfully, but these errors were encountered: