How to fix Refused to execute script from '' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

Anonymous
2023-12-18T16:08:44.39+00:00

Hi,

i hope you are doing well.

I have a custom webpart written in SPFx ReactJS, when i deploy it, i have this error message :

Refused to execute script from 'https://publiccdn.sharepointonline.com/mytenant.sharepoint.com/sites/cor…-4ac6-9e8d-156baba403c4/RegionsDepartmentsComponentWebPartStrings_en-us.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

in the previous one I did not have this error message

Thanks in advance

Microsoft 365 and Office SharePoint Development
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-12-21T01:31:04.2866667+00:00

    Hi @AIT BAALLAL Mostafa,

    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    Issue Symptom:

    SPFx ReactJS return Refused to execute script from '' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

    Solution:

    Clean and repackage the solution fixed the issue, could run following cmdlet

    gulp clean --ship
    gulp build --ship
    gulp bundle --ship
    gulp package-solution --production
    

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-12-19T02:31:30.6766667+00:00

    Hi @AIT BAALLAL Mostafa,

    Per my research, I found out that it seems to be an error that you obtain in browser DevTools, and it's somehow related with your CSS libraries/files. You could refer to the following similar issues

    https://stackoverflow.com/questions/49406057/refused-to-apply-style-from-because-its-mime-type-text-html-is-not-a-supp

    https://github.com/rails/webpacker/issues/1651


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Anonymous
    2023-12-20T15:44:39.7866667+00:00

    thank you @RaytheonXie_MSFT again

    I resolve it by executing :

    gulp clean --ship

    gulp build --ship

    gulp bundle --ship

    gulp package-solution --production

    Clean and --production are important, because in the last time i ignore the warning :

    Warning - [package-solution] This is not a production build (--ship or --production), therefore the "includeClientSideAssets" setting will be ignored.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.