-
Notifications
You must be signed in to change notification settings - Fork 5
TS2688 Cannot find type definition file for 'node_modules'. #5
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
TS2688 Cannot find type definition file for 'node_modules'. #5
Comments
@petermuessig , do you have any idea? |
@Fjaoos Can you please try the following change? "typeRoots": [
"./node_modules/@types",
"./node_modules/@openui5/ts-types-esm"
], with "typeRoots": [
"./node_modules/@types"
],
"types": [
"@openui5/ts-types-esm"
], (or replace "openui5" with "sapui5", if you used SAPUI5 in the generator) |
Hey @akudev I've tried it locally as well (did some thinking yday as well) the change you described works for me. I've checked several issues, the ts docs regarding typeroots/types, blogs and what not, the most prominent probably being microsoft/TypeScript#27956. If it isn't too much or too long to explain, may I ask why it is that this config change is working? I'm trying to make some sense of it for the future. ^^ Appreciate it! |
Hi @akudev, Regards |
@Fjaoos , @wridgeu I'll let you know and document it once I figured out why it works. ;-) |
@wridgeu @Fjaoos @lemaiwo Ok, it's now understood - albeit a bit lengthy to explain, as several tricky details come together: A few months back (in 1.100) the UI5 types started coming with a package.json dependency to the jQuery and qUnit types. The goal was to a) free app developers from explicitly requiring them and to b) ensure the version of those types is included which best fits the jQuery/qUnit version actually embedded in UI5. Because the "typeRoots": [
"./node_modules/@openui5/ts-types-esm",
"./node_modules/@types"
], This was the recommendation since 1.100. But this fcl app template and also the original TypeScript Easy-UI5 template used for the UI5con workshop, where the same issue was discussed, had for some reason (probably because it was formerly required) its own dependency to the jQuery types. And still has. The official documentation for "typeRoots" does not mention it at all, but an old comment by the TypeScript dev team lead made me understand that TypeScript expects ALL folders which are direct children of a "typeRoot" to be "types folders" and that each such "types folder" MUST have an It basically complains that the The solution proposed above works because the OpenUI5 types are no longer in the "typesRoot" section, but in the "types" section. TypeScript hence just loads the types and is happy, ignoring the "typeRoots": [
"./node_modules/@types"
],
"types": [
"@openui5/ts-types-esm"
], However, there is one drawback: as mentioned before, making "typeRoots": [
"./node_modules/@types"
],
"types": [
"@openui5/ts-types-esm",
"jQuery"
], And indeed right now it LOOKS LIKE the "typeRoots" entry for the standard types might not be needed at all, so the following might also suffice as solution: "types": [
"@openui5/ts-types-esm",
"jQuery"
], On the other hand we know now what the error message was about and how to avoid it (only require the jQuery types ONCE). When doing so, the original way of pointing to the types continues to work fine: "typeRoots": [
"./node_modules/@types",
"./node_modules/@openui5/ts-types-esm"
],
We haven't made up our mind yet which way to recommend and not fully tested all implications, but at least it is now pretty clear what happens and what the available options are. |
wow @akudev. Thank you so so so much for the detailed explanation. Much appreciated!
When looking into this myself I've had various "suspicions" regarding the
I'd say this issue should then be kept open as reference point or until it is either documented somewhere "more central" where it'd make sense or a recommendation can be given? |
Thank you @akudev ! Should we already change the template? Or do we wait for further recommendations from the UI5 team? |
@wridgeu @lemaiwo We are going back to "typeRoots" for both the default @types folder as well as the UI5 types. And making sure the templates don't have a jQuery types dependency (which they shouldn't have had anymore, anyway). Here I have added a summary of the issue in a more central place, so from my perspective this issue report could now be tied to the settings in THIS template (both jQuery and qUnit) and be closed once the dependencies are removed. |
Remove jQuery dependency and set default and UI5 types as "typeRoots". Fixes the issue reported for the other template at ui5-community/generator-ui5-ts-app-fcl#5
To avoid the issue reported at ui5-community/generator-ui5-ts-app-fcl#5 for the other template.
This is a sort of never-ending story. With TypeScript 5.1 the lookup behavior was changed when error TS2688: Cannot find type definition file for '@sapui5/types'.
The file is in the program because:
Entry point of type library '@sapui5/types' specified in compilerOptions
tsconfig.json:16:9
16 "@sapui5/types",
~~~~~~~~~~~~~~~
File is entry point of type library specified here. The current recommendation for tsconfig in TypeScript 5.1 onwards (but also usable in lower versions) is hence not to set any |
Typescript 5.1 onwards to include @sapui5/types
|
@prasanthkarukkuvel Well, actually - as mentioned above - the recommendation is not to set "types": ["@openui5/types", "@types/qunit"] Your suggestion, however, is not wrong and will also work, but one might still run into this problem. The official suggestion, on the other hand, means that one has to remember to add all additional types explicitly. So both ways have their advantages and drawbacks and we also had some discussions what to favor at the moment. |
Hi @akudev, as this might be an ongoing topic (like it already has been now :D), maybe it makes sense to have an ongoing Github "Discussion" opened somewhere or have a |
@wridgeu While the known issues already covered this topic, I have added an FAQ page with a section on it. |
Awesome, thank you! Also good to know that there is a known issues section - never noticed 😅 |
@akudev Edit: Turned out to be an issue related to the project's yarn setup. |
@BenReim I have mentioned this problem in the second section of the known issues document. |
For reference, another extended write-up of this topic with a bit more explanation than the compact "known issues" section: SAP/ui5-typescript#461 (comment) |
Hi,
I used the yo generator to create a TS app but it shows the following error when you execute tsc --noEmit:
error TS2688: Cannot find type definition file for 'node_modules'.
The file is in the program because:
Entry point for implicit type library 'node_modules'
The app has been generated with default values only.
I did some research but could not come up with any solution.
The text was updated successfully, but these errors were encountered: