I am making a websocket webgame. I am trying to standardize data going over the websocket via some shared "Action" objects. I am using docker volumes to share a "shared" directory between two different containers, and tsconfig.json files to create an alias for easier use. This works fine for client, but I keep getting an error from the server.
The command I'm entering npm run dev:
(base) omitted@omitted CS5001-Scribble-Beasts % npm run dev
> scribble-beasts@1.0.0 dev
> docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
The error I'm running into:
server-1 | import { Actions, ActionType, ParseAction, type AnyAction } from "@shared/actions";
server-1 | ^
server-1 |
server-1 | SyntaxError: The requested module '@shared/actions' does not provide an export named 'ActionType'```
Code: https://github.com/2025-Senior-Design-Project/Scribble-Beasts/tree/room-system
(if you want to try and run this yourself, check out CONTRIBUTING.md)
/client
/server
/shared
docker-compose.yml
docker-compose.yml
server:
build:
context: ./server
dockerfile: Dockerfile
volumes:
- ./server:/app
- ./shared:/shared
server/package.json
"type": "module",
"main": "dist/server/src/index.js",
"exports": "./dist/*.js",
"scripts": {
"start": "node dist/server/src/index.js",
"dev": "tsx watch src/index.ts",
server/tsconfig.json
{
"compilerOptions": {
"lib": ["es2024", "ESNext.Array", "ESNext.Collection", "ESNext.Promise"],
"module": "esnext",
"moduleResolution": "bundler",
"target": "es2017",
"outDir": "./dist",
"baseUrl": ".",
"paths": {
"@shared/*": ["../shared/*"]
},
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*", "../shared/**/*"],
"exclude": ["node_modules", "dist"]
}
../../../../shared) it shows the same errorError: Cannot find module '/app/src/lib/scripts/roomless-handler' imported from /app/src/index.ts)If you have a conflicting setup between your local setup and container setup with ts, you can create a docker.tsconfig. To avoid trying to keep two different tsconfig files update to date, just have your docker version extend the local one.
Specifically:
docker.ts.config
{
"extends": "./local.tsconfig.json",
"compilerOptions": {
"baseUrl": "." // change to whatever the directory difference is
}
}
Then change the docker-compose to rename your local tsconfigs to their docker versions
docker.tsconfig -> tsconfig
tsconfig -> local.tsconfig
volumes:
- ./server/docker.tsconfig.json:/app/tsconfig.json
- ./server/tsconfig.json:/app/local.tsconfig.json
This allows your docker.tsconfig to be loaded on just your container, while leaving your local setup as-is