Sign in to follow this  
mike perry

Multiplayer game - the "script" element could not be loaded

Recommended Posts

How do you configure the server for this template ? =>
I'm trying to do it by following this tutorial =>
I added two dependencies: nodemon and express.
I created the server.js file with the server configuration.

const express = require('express')
const app = express()
const server = require('http').Server(app)
const path = require('path')

app.get('/', function(req, res) {

server.listen(8081, function() {
console.log(`Listening on ${server.address().port}`)

In the package.json file, I added a command to start the server:

nodemon src/server/server.js

The server starts correctly but the indicated html file can not read the scripts (" The load failed for the "script" element with the source vendor.js and app.js").

Project structure: r4QcXoJ.png

Share this post

Link to post
Share on other sites

Thanks for reply.
I solved this problem by indicate to the folder in which the scripts are located .
In my case it was a folder called 'dev'.
Adding this line solved the problem:

app.use('/dev', express.static('dev'))

Additional question
Is there any way to run webpack only for build scripts not for running webpack server?
The node server needs scripts to open the HTML file correctly.
Scripts are built by running webpack in development mode.

Is it good practise if I start webpack and node server with one command?
Something like below (using "start").

    "start": "concurrently --kill-others \"npm run dev\" \"npm run server\"",
    "dev": "webpack --mode=development",
    "deploy": "webpack  --mode=production --config webpack.production.config.js",
    "server": "nodemon ./src/server/server.js --exec babel-node",


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.