-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
"error TS2304: Cannot find name" after updating to 7.0.0 #615
Comments
I have the same issue, my custom types files are not loaded anymore with the version 7. |
A major version means breaking changes. If something breaks, you can check the changelog or commits to see what happened. See https://github.com/TypeStrong/ts-node/releases/tag/v7.0.0 and the notice in the README. If they aren't clear, feel free to clarify them. If you'd like the old behaviour for now, you can use Edit: Reference to issue which prompted changing the behaviour - gulpjs/interpret#51. |
@weswigham Would you be kind enough to share the recommended way someone should include these files into their |
Yes, I would like to know how is the proper way. |
Why make a major release so quickly? I do agree that, as @weswigham says, "the build orchestrator is not part of the build it orchestrates", but the fix is kind of on the extreme side. Why not at least try taking some useful parts out of the Sticking to v6 for now, since I don't want to:
It's possible that I'm in the tiny minority here, but the discussion was way too short for this change, IMO. |
@jeremejevs You assume I haven't thought about this for the past three years of working on this module, which I (unfortunately) have. There's been many iterations on the "correct" approach, but I agreed this one was the most appropriate today given
You can't just magically introduce a flag that controls which files get type checked. I'm not sure how you believe those flags would play into this? Are you expecting You don't even need to maintain a separate |
FWIW, I'm going to have to assume you're having issues with trying to "global" types into your project. Those aren't particularly recommended today as it makes your code fragile to conflicting types and unable to interop with dependents. You can instead put your types in modules, export and import them where needed instead of having them "everywhere". Another thing, you can use Edit: The existing issue for reference (note it never even finished): |
@blakeembrey Poor reading skills this time of day + didn't look at the diff. Interpreted "Skip loading What do you mean by "global" types? I have a few of these: // typings/some-npm-package.d.ts
declare module "some-npm-package" {
// ...
} And |
Feel free to submit corrections to how it's phrased. I know I can be terrible at that and don't typically spend enough time thinking about all the ways it's interpreted. As for Update: Failing to get my test case to fail, so haven't been able to replicate the issue yet. |
@jeremejevs Found the issue - looks like your |
How can we pass |
@salemdar Maybe I missed something but I do not see any way to get
This is what I'm using for the
I've decided to go with If you do want Gulp to run type checking and use |
@blakeembrey Thank you for taking time to look into this. Decided to investigate this myself, and wow, still got some misconceptions. Everything was working, so I was sure I had it all figured out... Indeed, The "fix" is to put this in place of "baseUrl": ".",
"paths": { "*" : ["typings/*"] } And translate all typings from // typings/some-npm-package.d.ts
declare module "some-npm-package" {
const x: string;
export = x;
} To this: // typings/some-npm-package/index.d.ts
declare const x: string;
export = x; I'm choosing this approach because I always wanted my typings to look the same as what you would find on DefinitelyTyped, and now it's possible, and it works with both I also have typings like this: // typings/svg.d.ts
declare module "*.svg" {
const x: string;
export default x;
} These are okay to leave as-is, since they make sense only in the context of a bundler like Webpack, and I'm glad this change broke my stuff, now I have a better config and a better understanding of it, thanks. Edit Have fiddled around some more, and found out that Adding |
I’m not as glad it broke things for people (it’s one of many “the lesser of two evils” but trying to figure out which evil is which is the hard part), but I’m thankful for your investigation work! |
I really feel like there should be more context in the release notes for a major version. |
For the lazy webpack users that are running into this issue: Assuming the following....
{
"scripts": {
"start": "webpack"
}
} Simply change it to this and it'll work like before: {
"scripts": {
"start": "TS_NODE_FILES=true webpack"
}
} |
@lddubeau: You can also set an environment variable instead of @blakeembrey: Whichever evil you choose, describing it more explicitly in the release notes would have saved us all a lot of time! |
Feel free to submit an issue with a better description that you’d like to see. |
From my admittedly limited understanding, maybe:
But then, putting the declarations in the correct folder like @jeremejevs suggests seems to work too. EDIT: I haven't been using the |
@jeremejevs You are not using
I'm facing this problem when my
|
@ljani Sorry, I'm not. It appears that my "fix" clashes with the assumptions that |
@jeremejevs Thanks for the confirmation! I wanted to make sure it was not a misconfiguration on my part. |
@ljani How did you use these definitions before? If they're still global (e.g. |
They're global. I didn't even try |
@ljani That should work 👍 |
@blakeembrey Great! Thanks for letting me know. The first time I tried TypeScript, I think I forgot to include |
@blakeembrey It works, thanks again. Do you happen to know why at least TS language service gets confused if
It works fine if I add the file directly to the modules. EDIT: Nvm, it might be something else. It seems that my |
What about ambient module declaration for module augmentation? declare namespace NodeJS {
interface Global {
TypeGraphQLMetadataStorage: import("../metadata/metadata-storage").MetadataStorage;
}
} I've tried the |
@19majkel94 Can you share your configuration so we can see why it didn't work? @ljani Thanks for your investigations! It'd be worth adding a section to the README on how to set this up correctly, I'll try that tonight 😄 |
@blakeembrey It doesn't work because Here's quick reproduction gist: |
@19majkel94 That's not true, |
@blakeembrey So any idea why the gist is not working? 😕 |
@19majkel94 There's documentation and links in this thread pointing out what you've run into. You need to make it a directory and use |
I'll be working this week on improving documentation/introduction on how to use these features in TypeScript - it's definitely not clear from the TypeScript side given the number of comments/issues. |
Thanks, it's awful but at least it works - I wonder how |
@ljani Could I possibly see your |
@samjmckenzie Sure, this one is from a monorepo where the
The In Hope this helps. |
Thanks, but unfortunately I can't get it working. Oh well. I will just have to keep using the |
Add my own typedefs for file via typeRoots in tsconfig. https://www.typescriptlang.org/docs/handbook/tsconfig-json.html TypeStrong/ts-node#615 (comment)
Fixes failing tests on node 10 TypeStrong/ts-node#615
Actually the way Also now that I come to think about this once agan, is this test wrong? Shouldn't it be EDIT: After initial testing, my build time was reduced from ~120 seconds to ~75 seconds after I removed the |
@ljani The test is correct. That’s a runtime error, not a compilation error. As for lookups, just don’t use the wildcard too heavily - there’s a difference between |
Ah, right. However, if I remove the whole EDIT: the output is the same:
EDIT2: If I remove EDIT3: After all, I moved back to EDIT4: I don't know. |
I updated ts-node from 6.2.0 to 7.0.0 and I started to get the following error:
It looks like this version is not able to find my custom type definitions. I recently started to learn typescript so I'm not sure if what I'm doing is good practice, this is my folder structure
Y put my types inside *.d.ts files and nothing more, this worked before updating.
Not sure if this can help but here is my .tsconfig
The text was updated successfully, but these errors were encountered: