I wan't to import a javascript class in my server.js file so I tried:
import Player from './classes/model/Player.js';
Problem then I get the error:
SyntaxError: Cannot use import statement outside a module
So I wrote this in my package.json:
"type": "module",
Problem then I get the error:
ReferenceError: require is not defined in ES module scope, you can use import instead
I think this is because I'm using require in my server.js file:
const express = require('express');
const http = require('http').Server(express);
const io = require('socket.io')(http, {
cors: {
origin: '*'
},
pingTimeout: 60000
});
Problem here is that I don't know how to use socket.io without this require syntax.
So I tried using require instead of import and without the "type":"module" like so:
const Player = require('./classes/model/Player.js')
Then I get the error:
SyntaxError: Unexpected token 'export'
So I removed the export default from my player class.
I don't get an error now, but my Player constant is just an empty json like so {}
I don't know what to do anymore...