0

I've been having a lot of difficulty with trying to import parts of a Javascript library into a .html file. Everytime I fix a problem I run into a new one. I am currently running the .html file on a localhost after installing apache, but am getting two error messages in the console that I don't know how to fix when I try to install files from a Javascript library. These are the error messages:

Loading module from “http://localhost/js/core/MinimalStim” was blocked because of a disallowed MIME type (“text/html”). Loading failed for the module with source “http://localhost/js/core/MinimalStim”.

Loading module from “http://localhost/js/core/WindowMixin” was blocked because of a disallowed MIME type (“text/html”). Loading failed for the module with source “http://localhost/js/core/WindowMixin”.

Loading module from “http://localhost/js/util/Util” was blocked because of a disallowed MIME type (“text/html”). Loading failed for the module with source “http://localhost/js/util/Util”.

Loading module from “http://localhost/js/util/PsychObject” was blocked because of a disallowed MIME type (“text/html”). Loading failed for the module with source “http://localhost/js/util/PsychObject”. localhost:16:1

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content = "ie=edge">
    <title>Today's date</title>
</head>

<body>
    <h1>"Today's date"</h1>
    <script src="js/visual/VisualStim.js" type="module"></script>
    <script src="js/core/MinimalStim.js" type="module"></script>
    <script src="js/core/WindowMixin.js" type="module"></script>
    <script src="js/util/Util.js" type="module"></script>

</body>

</html>

Also, is there anyway to install an entire library at a time rather than separate files from the library, because every time I try and import a file from that library, that file imports other files from the same library, meaning that I then have to import that file from the library as well. I can't find any information about this anywhere online.

blulu
  • 1
  • 1

1 Answers1

0

You can use https://parceljs.org/ or webpack to combine files and generate single. Parcel is light weighted. Can be done in minimal lines. WebPack required little effort to setup

npm install -g parcel-bundler

Regarding the loading issue, seems like you have to enable apache static server. Check your configuration.

Another reason could be PORT, by default port is 80. Try some other port.

Serving static files through apache

You can use http-server, light weight server to serve static contents.

https://www.npmjs.com/package/http-server

xdeepakv
  • 7,835
  • 2
  • 22
  • 32