21

I'm working with asp.net core web app and trying to use libmam to manage client-side libs. I'm turn on "Enable Client-Side Libreries on Build" and write some code in libman.json:

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "defaultDestination": "wwwroot/lib",
  "libraries": [
    {
      "library": "jquery@3.3.1",
      "destination": "wwwroot/lib/jquery/"
    }
   ]
}

Restoring libs works fine if I'm using "Restore Client-Side Libraries". But when I'm trying to build application I'm getting an error:"libman.json : error LIB002: The "jquery@3.3.1" library could not be resolved by the "cdnjs" provider".

How can I solve the problem?

Natalia
  • 313
  • 2
  • 8

1 Answers1

10

So the reason, at least from what I've found, is that the library no longer exists or is not being seen by "cdnjs" provider.

The best way to deal with this is to update the library to a library that "cdnjs" does support. If you in fact already have the library installed consider using the "Disable libman" section.

The below instructions are being done on Visual Studio 2022, mileage may vary for other versions. If you have any issues consider using the "Re-add/Update" section.

Disable libman

  1. Right click libman.json

  2. click on Disable Client-Side Libraries on Build

enter image description here

Update your library

  1. In your libman.json move your cursor over to the left most side of the file but to the right of the line numbers

  2. A little light bulb should show up.

enter image description here

  1. Click on the down arrow

enter image description here

  1. You'll be greeted with a couple of options, Click on Check for updates (in my case I already have the latest version.)

  2. Select the version you want and VS will autofill the version on that line.

Re-add/update your library.

  1. In the Solution Explorer, right-click on the name of your Project (This is usually the <NameOfProject>.csproj file)
  2. select Add -> Client-Side Library...

enter image description here

  1. In the dialog box that appears, type jquery@, and then a dropdown list should appear allowing you to select the version you want.

enter image description here enter image description here

  1. Click on the Install button and that will add the new library to your libman.json file. Make sure to also delete the previous library if Visual Studio doesn't do that for you automatically.

enter image description here

tisaconundrum
  • 2,156
  • 2
  • 22
  • 37
  • That way I found out the library with version I needed no longer exists, but I could install newer version – Dariusz Jun 24 '22 at 13:42
  • 1
    I'm having the exact same issue but I am able to restore all libraries successfully. I can also see they are available in cdnjs. However, when I try to build the project, the error appears and is inconsistent in that the library being referenced changes randomly. We also had a case where my coworker was getting the error on his machine but I wasn't on mine. Any thoughts? – Lukas Jul 14 '22 at 13:54
  • @Lukas I had similar cases with my coworker as well. This could be related to the IDE itself. I may recommend utilizing the Libman CLI. You can do your `clean` and your `restore` straight from the command line to fix some of the libraries. Install by using `dotnet tool install --global Microsoft.Web.LibraryManager.Cli` Learn more here https://learn.microsoft.com/en-us/aspnet/core/client-side/libman/libman-cli?view=aspnetcore-6.0 – tisaconundrum Jul 15 '22 at 17:27
  • 4
    Thanks for the response. I actually ended up finding a [thread about this issue](https://github.com/aspnet/LibraryManager/issues/685) and lots of people have been experiencing it. They are slowly rolling out a change to the cdnjs API and it's causing the errors. My solution was to update the `Microsoft.Web.LibraryManager.Build` NuGet in my project as they have released a new version. This might be something good to mention in your answer to improve it, or I can. – Lukas Jul 15 '22 at 18:38
  • Yes feel free to make the edits :) – tisaconundrum Jul 15 '22 at 18:54