Unable to connect CSS/JS files to the HTML page

I followed a tutorial to set up my project which can be found here:

However, when I run the gulp file, the CSS/JS files are not being linked. I have applied a background color to the body but it is not showing up.

I installed Bootstrap 4 using npm and added a gulpfile for processing. Here is the code for the gulp file:

var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'])
.pipe(sass())
.pipe(gulp.dest("src/css"))
.pipe(browserSync.stream());
});

// Move the javascript files into our /src/js folder
gulp.task('js', function() {
return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js', 'node_modules/popper.js/dist/umd/popper.min.js'])
.pipe(gulp.dest("src/js"))
.pipe(browserSync.stream());
});

// Static Server + watching scss/html files
gulp.task('serve', gulp.series('sass', function() {

browserSync.init({
server: "./src"
});

gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], gulp.series('sass'));
gulp.watch("src/*.html").on('change', browserSync.reload);
}));

gulp.task('watch', function() {
    gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], gulp.series('sass'));
});

gulp.task("default", gulp.series(gulp.parallel("js", "serve", 'sass')));

Even though the localhost index page opens, the CSS/JS is not being applied:

CSS code: body {background-color: #70501f; }

An error is displayed in the console:

Refused to apply style from 'http://localhost:3000/src/css/bootstrap.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. (index):1 Refused to apply style from 'http://localhost:3000/src/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

CSS:

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<link type="text/css" href="/src/css/bootstrap.css" rel="stylesheet">
<link type="text/css" href="/src/css/style.css" rel="stylesheet">

JS:

<script type="text/javascript" src="/src/js/jquery.min.js"></script>
<script type="text/javascript" src="/src/js/bootstrap.js"></script>
<script type="text/javascript" src="/src/js/popper.min.js"></script>

If you can help, please check out my code on GitHub: https://github.com/pradeepmpatel/bootstrap4tuts

Thank you, PP

Answer â„–1

In my opinion, the issue with the MIME Type might be caused by an incorrect CSS path. It seems like it's attempting to display an error instead of the actual CSS file because the MIME type doesn't match. Double-check your paths for both CSS and JS files, it could be either ./src or ./node_modules.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying object properties within another object obtained from an API request in a React component

Dealing with API data can be tricky, especially when there are nested objects involved. I've encountered an error message stating 'undefined is not an object (evaluating 'coin.description.en')', as the description property of the c ...

What causes the sudden change in value of this array?

I can't seem to figure out what's going on with this question. It might be something silly, but I haven't been able to find any clues. Here is the array in question: const superVillains = [ { value: '1', label: 'Thanos&apo ...

Utilize itextsharp to transform HTML into PDF files

When I try to convert HTML to PDF using iTextSharp, the CSS styling I apply to the webpage does not get carried over to the converted PDF file. Here is the CSS code I am using: <style type="text/css"> .cssformat { ...

I am facing difficulties in installing node packages using npm install

Trying to install node packages using npm, but encountering an issue. When I run the command, the output is: up to date, audited 356 packages in 7s found 0 vulnerabilities I have listed the dependencies in my package.json file like so: "dependencies& ...

Learning how to interpret data within configuration files (.properties) using JavaScript

I'm trying to retrieve data from a configuration file (.properties) in my code. The structure of my configuration file is as follows: maxTime = 60 upVotePostMaxTime=60 However, I am unsure of how to read this configuration file using JavaScript. Is ...

Design a visually stunning image grid with the use of Bootstrap 4

I am having difficulty creating an image grid with consistent spacing between columns, like shown in the image below: https://i.sstatic.net/azsxa.jpg The issue I am facing is aligning the right margin (red line), as illustrated below: https://i.sstatic. ...

Disappear the loading icon once all children have finished rendering

I'm facing a minor issue with rendering in React and struggling to find a solution. Here's what's happening: My component acts as a wrapper for multiple entries, like this: class MyWrapper extends Component { renderItems() { return ( ...

Failure to execute after Ajax success

Currently working on a login page using Spring MVC on the server side and JS/Ajax on the client side. I'm facing an issue where the server code executes but does not return anything. <script type="text/javascript"> $(function() { $( ...

Using JQuery Datatables to output HTML based on JavaScript conditional logic

I am presently working on a project that involves using JQuery Datatables to display my data. Within this project, I am utilizing the datatables render method to format the data before it is displayed. However, I have encountered a challenge where I need t ...

What is the process for including a version number in npm pack?

I've been working on deploying TeamCity with NPM pack, and I've noticed that it's packaging everything up as filename-0.0.0.tgz. So, I decided to switch to the command line to troubleshoot before running it through TC. When I run npm pack i ...

Multiple CSS styles are being employed simultaneously to render the webpage

Currently, I am utilizing JavaScript to choose different CSS styles for various accessibility options such as black on white text and larger text. The issue I am facing arises when switching the CSS sheet, as elements from previously selected sheets are st ...

Transforming a single object into multiple arrays using AngularJS

Just starting out with AngularJS and I've got some data that looks like this { day1: 0, day2: 0, day3: 0, day4: 2 } Is there a way to convert this data into arrays structured like below? [     ["day1": 0],     ["day2": 0],   ...

JavaScript Loading Screen - Issues with window.onload functionality

I am currently working on creating a loading screen for my project. I need to use JavaScript to remove the CSS property "Display: none" from the page, but for some reason, my code is not functioning as expected. The Issue: I discovered that using window. ...

Managing concurrent users updating the same form on a web application

Imagine a scenario where user A opens a form with pre-filled data. While user A makes changes to the form data, user B also opens the same form with the data intended for user A. Just as user B begins modifying the data, user A clicks on the submit butto ...

What steps can I take to make sure that the asynchronous initialization in the Angular service constructor has finished before proceeding?

Hello experts, can you advise on ensuring that asynchronous initialization in the service constructor is completed before calling other functions within the class? constructor() { var sock = new SockJS(this._chatUrl); this.stompClient = Stomp.ov ...

What is the reason for the binding event being triggered following the re-render of the setstate?

The Test component has a state of num. This component is designed to increase the value of num by 1 when a button is clicked. The button is linked to a self-increment method, and the keyup event is also connected to this method. When the method is triggere ...

I'm encountering an issue with fetching table data using AJAX, as I consistently receive an undefined value in Console.log every time I try to fetch req_id from the table. Can anyone help me

I am struggling to fetch the req_id from the table as it always shows undefined in Console.log(). Despite having a successful database connection and data availability in the table, I have attempted both GET and POST methods without success. My main goal i ...

Is it possible to customize the styling of certain fundamental MUI components using makeStyles?

:D This is my first time embarking on a project from the ground up using react and MUI. I've been curious if I have set it up correctly. My goal right now is to incorporate some styling using makeStyles for certain components provided by Material UI ...

React - Show loading screen during AJAX request

While some questions are still loading, my component has already fully loaded. I successfully created the loading screen BEFORE the component load, but now I'm struggling with implementing it after the fact. My current approach involves making an aja ...

Mastering the art of tab scrolling in VueJS using Bootstrap-vue

Currently, I am working on a VueJS project that utilizes bootstrap-vue. The issue I am facing is that when rendering a list of tabs, it exceeds the width of its parent container. To address this problem, I aim to implement a solution involving a set of but ...