Im creating a multiplayer dungeon crawler game in typescript. I have three typescript projects, one server, one client, and a common project where the idea is that both the server and the client can share code. One example is the creation of the dungeon which needs to be done at both the server and the client:
import Dungeon from "./node_modules/@mikewesthad/dungeon/dist/dungeon";
export const createDungeon = (randomSeed: string) =>{
const dungeon = new Dungeon({});
return dungeon
}
Importing the createDungeon method in the client works fine, however when importing it in the server, all is well until i start the server, i get the error "Cannot find module '../../common/dungeonUtils'"
Im geussing i have something not configured correctly,
The tsconfig.json file for the server looks like this:
{
"compilerOptions": {
"target": "ES2020",
"module": "Node16",
"rootDir": "src",
"outDir": "dist",
"allowJs": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"references": [
{ "path": "../common" }
],
"include": [
"src/**/*"
]
}
The tsconfig.json file for the client looks like this:
{
"compilerOptions": {
"target": "es2016",
"module": "es6",
"strict": false,
"noImplicitAny": false,
"noEmit": true,
"allowJs": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
},
"typeRoots": [
"node_modules/@types",
"node_module/phaser/types"
],
"types": [
"phaser"
]
},
"references": [
{ "path": "../common" }
],
"include": [
"src/**/*"
]
}
The server is started using the following:
"scripts": {
"start": "npm run dev",
"dev": "npm run tsc && npm-run-all --parallel dev:*",
"dev:tsc": "tsc --watch",
"dev:nodemon": "nodemon dist/server.js",
"tsc": "tsc --build"
},
I have tried importing typescript files that reside in the server project, and that works fine.