Uncaught TypeError: require.config is not a function CSS and Javascript files are not loading after Magento 2 installation




Uncaught TypeError: require.config is not a function
 and Javascript files are not loading after Magento 2 installation




Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/extjs/resources/css/ytheme-magento.css Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/images/magento-icon.svg Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/extjs/resources/css/ext-all.css Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/requirejs/require.js Failed to load resource: the server responded with a status of 404 (Not Found)
requirejs-config.js:65 Uncaught TypeError: require.config is not a function
localhost/:39 Uncaught TypeError: require.config is not a function
localhost/:87 Uncaught TypeError: require is not a function
localhost/:286 Uncaught TypeError: require is not a function
localhost/:418 Uncaught TypeError: require is not a function
localhost/:463 Uncaught TypeError: require is not a function
localhost/:504 Uncaught TypeError: require is not a function
localhost/:527 Uncaught TypeError: require is not a function
localhost/:550 Uncaught TypeError: require is not a function
htdocs/pub/static/adminhtml/Magento/backend/en_US/images/magento-icon.svg Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/semibold/opensans-600.woff2 Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/admin-icons/admin-icons.woff2 Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/regular/opensans-400.woff2 Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/bold/opensans-700.woff2 Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/admin-icons/admin-icons.woff Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/semibold/opensans-600.woff Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/bold/opensans-700.woff Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/regular/opensans-400.woff Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/admin-icons/admin-icons.ttf Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/bold/opensans-700.ttf Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/regular/opensans-400.ttf Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/fonts/opensans/semibold/opensans-600.ttf Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/extjs/resources/css/ytheme-magento.css Failed to load resource: the server responded with a status of 404 (Not Found)
htdocs/pub/static/adminhtml/Magento/backend/en_US/extjs/resources/css/ext-all.css Failed to load resource: the server responded with a status of 404 (Not Found)



In magento 2.x version the below messages you might encounter frequently. When you develop a new module or make some changes and try to publish it these error might occur saying Uncaught type error
Require.config is not a function
Css and JavaScript files will not load access the website is broken. When you try to install new magento copy in your local machine after completion of the setup this error might occur. All the menus are broken. Home page is not aligned. Products page are not displayed properly. Buttons click is not working.


To solve the error I tried the following steps in my local setup. I navigated to var folder and check the logs. Then delete the contents of cache folder and open a command prompt from your start menu.

To open a command prompt you can type ctrl+R, a box will open and here you can type the keyword cmd.

It will open a black screen with a cursor blinking. Now you need to navigate to the path where magento setup files are present. To navigate to the folders you can type the below command

cd <path>
Here <path> needs to be replaced with your magento setup root path. Once you navigate to the root folder you can run the following commands

php bin/magento setup:static-content:deploy

When you try to run the above command you might get an error saying php is not recognised as internal or external command. I have created a post how to fix this issue. Link to solve the php is not recognised as internal and extremal function is given below. You can visit the following link to check how to resolve this issue

https://www.freesamaya.com/2018/09/php-is-not-recognized-as-internal-or.html

after the above command is executed. Try to execute the below command

php bin/magento setup:upgrade

This upgrade command with enable and disable modules based on the coding you have done

php bin/magento setup:di:compile 

php bin/magento cache:clean

Clean command will remove the cache

I tried the above steps and was  able to solve the error and my css, Javascript got fixed on the page

Comments

  1. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    zuan education

    ReplyDelete

Post a comment