How can I fix the «TypeError: require.toUrl is not a function» issue?

Hi Dmitry

I am seeing this error in admin everywhere:

var a = require.toUrl('').split('/').slice(-4);
TypeError: require.toUrl is not a unction

It seems to be coming from file Df_Core/main.js Do you have any idea what this could be? Thanks!!

The require variable is the RequireJS library, and it should be available globally in Magento 2 JavaScript code.


It is not available in your case.

Possible reasons:

  • You made a wrong static content deployment
  • You have installed a low-quality extension which broke everything

How to fix it

  1. Recollect your wrong last action.
  • Reverse it.

Today I have reproduced this error in the backend and have fixed it in the mage2pro/core 2.4.50 version (mage2pro/stripe 1.9.13)

I faced same issue. I found that the issue is because of I was using “requirejs” in more functions than one. To fix this I have made global variable of jQuery for that particular page using this code

var jQueryVar;
    requirejs(['jquery'], function(jQuery) {
        jQueryVar = jQuery;
    });    

I hope this will help you.