0
votes

I configured require.js very well and it is working fine but when I added Identity Pages in ASP.NET Core 3.1 require js started to giving 404 error when loading script files, jquery, jquery-validation and jquery.validate.unobtrusive. When I check the console the path is wrong, and it is trying to find these files near require.js file directory (as you know it is default directory) but in my config file I configured path as very well and working in my other pages but not in identity pages.

Here my require.js config file

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: '../',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
    paths: {
        jquery: 'lib/jquery/dist/jquery.min',
        main: 'js/bundle/main.min',
        'jquery.validate': 'lib/jquery-validation/dist/jquery.validate.min',
        'jquery.validate.unobtrusive': 'lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min'
    },
    shim: {
        'jquery.validate': ['jquery'],
        'jquery.validate.unobtrusive': ['jquery', 'jquery.validate']
    },
    waitSeconds:0
});

It is working my other pages but not in identity when I check the 404 error the console error is;

RequireJs.js:5 GET https://localhost:44340/lib/RequireJs/jquery.js net::ERR_ABORTED 404

Shouldn't it use the requirejs config and shouldn't be the path is

RequireJs.js:5 GET https://localhost:44340/lib/jquery/dist/jquery.min.js like other pages ?

Thanks for any comment, Stay health folk :)

1
It looks like a script race for me. Maybe there is a script which is requiring a jquery before your config file is loaded. Can you check that?Damian Dziaduch
Thanks for your comment Damian Dzianduch, actualy I tried everything, I checked script race and I trid to load only one script jquery-validation and jquery but it is very weird that it is working on all pages except asp.net identity pages. URI path decay when I want to load identity pages.Dogan
Is there any difference between identity pages and regular pages? Is there any script which is loading only on identity pages?Damian Dziaduch
Hi Damian, thanks for your patient a day ago I found the asnwer, the reason is, jquery unobtrusive, becase all pages in asp.net core identity uses as default this npm and this npm is not require js oriented. So I change this library and used define() then this started to work fine, but it is really cumbersome one becasue there is not any error when you run app but it is working fine now.Dogan

1 Answers

1
votes

Eventually I found the answer. The problem is about the MVC default scripts which are in use by MVC framework spesifically in scaffolded items like identitity pages. Identity pages uses jquery.unobtrussive as default for showing warning and errors to UI side. But this js library do not use require js "define" statement. If you re-engine this library you can see that the problem disappears.