Cannot find Type defination file for datatables.net

Cannot find Type defination file for datatables.net

singhswatsinghswat Posts: 20Questions: 7Answers: 0

In my VS 2019 unde my project I installed datatables.net-fixedheader nuget package
after installation i complied and its throwing the below error.

Is this related to any Jquery version?

Current JQuery version - 3.4.1 in my application

**"Severity Code Description Project File Line Suppression State
Error Build:Cannot find type definition file for 'datatables.net'. \Scripts\types.d.ts 8

Error Build:Cannot find type definition file for 'jquery'. \Scripts\types.d.ts 7 **

Any help is highly appreciated...

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    What version of datatables.net-fixedheader (and the datatables.net dependency) are being installed for you please?

    Allan

  • singhswatsinghswat Posts: 20Questions: 7Answers: 0

    Thanks @allan
    I installed 1.11.3 datatables using Nuget Package manager

    Even if i uninstall the fixed column header I still get the error... details below

    Error

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    That is really odd, as we do have a dependency in our Nuspec file for jQuery and the type definition file is also listed.

    Can you show me a screenshot of the DataTables part of the error please?

    Allan

  • HeavyB93HeavyB93 Posts: 3Questions: 0Answers: 0
    edited February 2022

    I don't know if anything was ever resolved here but I am experiencing the same issue. I have created a new, clean MVC Web Application in Visual Studio 2019. I have added bootstrap 5.1.3 and nothing else (default items still installed). The project will compile fine. When I add datatables.net 1.11.3 I get the following errors when compiling:

    I am using NuGet package manager to add packages to this application. I have used datatables.net before with bootstrap 4.6 w/o issue. Any thoughts?

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    I don't have a Windows machine with me at the moment, but if you were to now also add the jQuery Nuget, does that then resolve the error? That would indicate that our dependency is wrong or not getting resolved for some reason.

    Thanks,
    Allan

  • HeavyB93HeavyB93 Posts: 3Questions: 0Answers: 0

    Hi Allan, jQuerry is already installed. It is the 5th item in the last screenshot. This is such an odd situation. I am trying to experiment with NPM and NuGet to see if it provides a clue. I appreciate any guidance.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    I've just been digging into this with my Windows machine running VS2019 and goodness me, dependencies for Javascript / Typescript typing information is a total mess in Nuget!

    The first big issue is that Nuget doesn't install packages in their own directories. We reference types.d.ts in our Nuget packages - but each datatables.net package you install has its own one of those and they just keep overwriting each other!

    That we can solve by giving everything a unique file name across the packages.

    The next issue is the triple slash reference statements:

    /// <reference types="jquery" />
    /// <reference types="datatables.net" />
    

    these make sense in NPM because that refers to the package name. And I'd assumed that would be the case in Nuget as well, but nope... It would need to become the file name location for the types file (from step 1) - for example the second line might be:

    /// <reference types="jquery.dataTables" />
    

    which would reference the file jquery.dataTables.d.ts (renamed from types.d.ts).

    That is different from our NPM packages though, so we'd need have a second types file for Nuget with that include specified.

    But the real kicker is that there isn't a jQuery types definition file in the jQuery Nuget package. So there is no way to reference jQuery types. For this, we'd probably need to add a dependency on jquery.TypeScript.DefinitelyTyped and then reference ./typings/jquery/jquery.d.ts.

    Oof!

    I've filed an internal bug (DD-2469) for this piece of work and I'll ask Sandy to look at it when he is back next Thursday.

    Two options to get this working just now:

    1. Delete the types.d.ts file - it means no typing information, but it is totally broken as it is, so...
    2. Or use npm rather than Nuget.

    Allan

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    Thinking about it - a more immediate solution would be for us not to ship the typing files in the Nuget packages. The might be the way we go here.

    Allan

  • HeavyB93HeavyB93 Posts: 3Questions: 0Answers: 0

    Allan, thank you so much for the very good and detailed explanation. I should have also included that my application is ASP.NET MVC, not CORE.

    However, in waiting for your response, I did experiment to try and understand the situation better. What I found is that if I use NPM I can solve the issue, or more correctly make the compiler happy by doing the following two installs:

    npm install --save @types/jquery
    *removed the first 2 (of the 3 errors)

    npm install --save @types/node
    *finall error cleared and project compiled.

    I won't even being to explain how I got to these steps.....

    Again, I am using VS 2019 16.11.7

    Now, my question back to you is: am I really solving the issue by doing this hybrid / hack with NPM or am I just pacifying the compiler?

    I don't mind using NPM, but the UI in VS for NuGet packages is pretty good compared to cli stuff. Only thing is you have to use Gulp or something else to get all your css and such in the right place if you go the NPM route.

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin

    You aren't replacing the compiler, but rather using a second package manager. The issue is that Nuget isn't particularly well suited to Javascript packages. It can of course work, but it isn't specifically designed for it like NPM is. VS2022 includes npm by default by the looks of things, so VS is heading in that direction.

    I don't believe that this is a hack as such, but rather using a Javascript package manager for Javascript packages.

    That said, you aren't the first to run into this and I would like the Nuget packages to just work. I'll talk it over with Sandy, but I suspect we'll just remove the types from the Nuget packages, allowing them to work as simple Javascript packages.

    Allan

  • kyleegbertkyleegbert Posts: 1Questions: 0Answers: 0

    Ran into this as well - interested in the fix! :-)

  • sandysandy Posts: 913Questions: 0Answers: 236
    Answer ✓

    Hi @kyleegbert @HeavyB93 ,

    Apologies but this appears to have slipped off of my radar in the last few weeks. There is a bug raised for this (DD-2469 for my reference) and I'm going to take a look at it today. I'll report back here later with an update.

    Thanks,
    Sandy

Sign In or Register to comment.