10

Here I have included the javascripts but I got mime type is not valid :

     <script type="text/javascript" src="{{ asset('/dashboard/js/components.js') }}"></script>
      <script type="text/javascript" src="{{ asset('/dashboard/js/custom.js') }}"></script>

      <script type="text/javascript" src="{{ asset('/dashboard/vendors/slimscroll/js/jquery.slimscroll.min.js') }}"></script>
      <script type="text/javascript" src="{{ asset('/dashboard/vendors/raphael/js/raphael-min.js') }}"></script>
      <script type="text/javascript" src="{{ asset('/dashboard/vendors/d3/js/d3.min.js') }}"></script>
      <script type="text/javascript" src="{{ asset('/dashboard/vendors/c3/js/c3.min.js') }}"></script>

And I am getting the error below :

      The script from “http://localhost/Project/public/dashboard/vendors/flotchart/js/jquery.flot.pie.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.[Learn More] home
      Loading failed for the <script> with source “http://localhost/Project/public/dashboard/vendors/flotchart/js/jquery.flot.pie.js”. home:2091:1
      The script from “http://localhost/Project/public/dashboard/vendors/flot.tooltip/js/jquery.flot.tooltip.min.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.[Learn More]

What is the problem ? Please help.

Andrei Lupuleasa
  • 2,393
  • 2
  • 10
  • 27
DEBASHIS BAIDYA
  • 180
  • 1
  • 2
  • 12
  • 5
    probably `/dashboard/vendors/flotchart/js/jquery.flot.pie.js` and `/dashboard/vendors/flot.tooltip/js/jquery.flot.tooltip.min.js` don't exist – Jaromanda X Apr 12 '19 at 10:34
  • 1
    can you open js file in browser? http://localhost/Project/public/dashboard/vendors/flotchart/js/jquery.flot.pie.js. also see [here](https://stackoverflow.com/questions/48248832/stylesheet-not-loaded-because-of-mime-type) or [here](https://discourse.roots.io/t/mime-type-text-html-not-a-supported-stylesheet-mime-type/11636) – Vishwa Apr 12 '19 at 10:34
  • 1
    As Jaromanda said, you're probably getting 404 errors (as HTML, which is why the mime type is HTML rather than JavaScript). Side note: There's no need for `type` on your `script` tag if you're loading JavaScript, it's the default. – T.J. Crowder Apr 12 '19 at 10:36
  • 1
    If I remove the type on script tag it is not working also and in opera I am getting : Failed to load resource: the server responded with a status of 404 (Not Found) – DEBASHIS BAIDYA Apr 12 '19 at 10:45
  • 2
    there you go .. the files don't exist ... perhaps they need to be there – Jaromanda X Apr 12 '19 at 10:48
  • 1
    But the files are there. And i checked on windows 7 it is working. – DEBASHIS BAIDYA Apr 12 '19 at 10:53
  • 1
    Wow....Yes the files are not there...the .gitignore file was hiding the files. Thanks Jaromanda :) – DEBASHIS BAIDYA Apr 12 '19 at 10:56

3 Answers3

5

What worked for me: After a half day research i tried just to edit the JS file. Just put a new line (ENTER) after the first (commented) line and saved it.

It was jquery minified file with a comment on the beginning. In Firefox "Inspector / Network" the .js was displayed as 404 and MIME (text/html). The strange thing was that the other .js files in the same directory were OK. Hope that helps.

Tuba Ádám
  • 61
  • 1
  • 4
2

I faced the same problem for Node js application. Your scripts path starting with

/dashboard/js/components.js

so basically you have to use

const app = express()
const publicDirectoryPath = path.join(__dirname, '../public/')
app.use(express.static(publicDirectoryPath))
1

this is for nodejs user

use 404 middleware or any others last

app.use(function(req,res,next){
res.send('page does not exist')
})

if you use this before

app.use(express.static(path.join(__dirname,'static')))

it will throw same error

Dharman
  • 21,838
  • 18
  • 57
  • 107