0
votes

I am getting multiple errors when trying to access my application:

Refused to apply style from 'http://localhost:8000/styles.2466d75470f9c2227ee1.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Refused to execute script from 'http://localhost:8000/runtime.205c879ce8dbb57b9cca.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'http://localhost:8000/polyfills.ce2bae2f7a5e6e1939c2.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Refused to execute script from 'http://localhost:8000/main.510119795446e9da8a78.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Folder structure:

- main project folder
- - src
- - - config
- - - - express file
- - client
- - - build
- - - - index.html and other files after build

In express file I have this:

app.use(express.static('../../client/build/'));
app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, '../../client', 'build', 'index.html'));
});

What am I doing wrong?

1
http://localhost:8000/styles.2466d75470f9c2227ee1.css is hitting express.static not finding a matching file then moving on to app.get('*' and getting an HTML document. There's no way to know why those files don't exist. - Quentin
I get these errors when trying to access just localhost:8000 which should be redirected to index.html, or not? - Chris K.
You won't get those errors unless you load an HTML document (which is presumably http://localhost:8080/) and that HTML document triggers requests for the subsequent URLs to load CSS and JS that it depends on. - Quentin

1 Answers

0
votes

Problem was with app.use(express.static('../../client/build/'));

It should be app.use(express.static(path.join(__dirname, '..', '..', 'client', 'build')));