I’m running a docker application. One of my containers is running node + express + typescript and I face weird issue. I have a file that exports type and file that imports it. In my idee (vs code) there is no such error.
error: SyntaxError: The requested module ‘./account.js’ does not provide an export named ‘Account’
account.ts
export type Account = {
accountID?: string;
name: string;
description?: string;
balance?: number;
userID?: string;
};
index.ts
import { Cashflow } from "./cashflow.js";
import { Account } from "./account.js";
import { Goal } from "./goal.js";
import { createAccountAttrSchema } from "./createAccountAttrSchema.js";
import { updateAccountAttrSchema } from "./updateAccountAttrSchema.js";
import { createCashflowAttrSchema } from "./createCashflowAttrSchema.js";
import { updateCashflowAttrSchema } from "./updateCashflowAttrSchema.js";
import { createGoalAttrSchema } from "./createGoalAttrSchema.js";
import { updateGoalAttrSchema } from "./updateGoalAttrSchema.js";
export {
Cashflow,
Account,
Goal,
createAccountAttrSchema,
updateAccountAttrSchema,
createCashflowAttrSchema,
updateCashflowAttrSchema,
createGoalAttrSchema,
updateGoalAttrSchema,
}
compose.yaml (look at the rest-api service)
services:
rest-api:
build: ./rest-api
env_file: ./rest-api/.env
volumes:
# better dev experience
- ./rest-api:/app/
# to prevent dependencies errors
- rest-api_nm:/app/node_modules
ports:
- 3000:3000
depends_on:
# waits until db is ready
database:
condition: service_healthy
restart: true
# waits until keycloak is ready
keycloak:
condition: service_healthy
restart: true
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
interval: 10s
retries: 5
start_period: 30s
timeout: 10s
frontend:
build: ./frontend
env_file: ./frontend/.env
volumes:
# better dev experience
- ./frontend:/app/
# to prevent dependencies errors
- frontend_nm:/app/node_modules
ports:
- 4000:5173
depends_on:
rest-api:
condition: service_healthy
restart: true
database:
build: ./database
env_file: ./database/.env
volumes:
# for persisting db data
- db-data:/var/lib/postgresql/data
# file with initial sql queries
- ./database/init.sql:/usr/share/init.sql
# checks if db is ready for connections
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
retries: 5
start_period: 30s
timeout: 10s
keycloak:
build: ./keycloak
env_file: ./keycloak/.env
volumes:
# for importing keycloak realm on startup
- ./keycloak/import:/opt/keycloak/data/import
# for storing keycloak data
- keycloak-data:/opt/keycloak/data
ports:
- 5000:8080
depends_on:
# waits until db is ready
database:
condition: service_healthy
# checks if keycloak http server is running
healthcheck:
test: timeout 10s bash -c ':> /dev/tcp/localhost/8080'
interval: 10s
timeout: 10s
retries: 5
start_period: 60s
volumes:
rest-api_nm:
frontend_nm:
db-data:
keycloak-data:
Docker file for rest-api service
FROM node:22-alpine
RUN apk add curl
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
package.json
{
"name": "rest-api",
"version": "1.0.0",
"description": "rest api for expens",
"main": "index.js",
"type": "module",
"scripts": {
"build": "tsc",
"start": "NODE_ENV=production node dist/index.js",
"dev": "NODE_ENV=development tsx watch src/index.ts --clear-screen=true"
},
"repository": {
"type": "git",
"url": "git+https://github.com/LoRd123545/expens.git"
},
"author": "Kamil Abbasi",
"license": "ISC",
"bugs": {
"url": "https://github.com/LoRd123545/expens/issues"
},
"homepage": "https://github.com/LoRd123545/expens#readme",
"devDependencies": {
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.6",
"@types/pg": "^8.11.6",
"tsx": "^4.16.0",
"typescript": "^5.5.2"
},
"dependencies": {
"ajv": "^8.17.1",
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"pg": "^8.12.0",
"sequelize": "^6.37.3"
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "NodeNext", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */
"moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
"outDir": "dist", /* Specify an output folder for all emitted files. */
"noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"src/*": ["src/*"],
"@utils/*": ["src/utils/*"],
"@config/*": ["src/config/*"],
"@middleware/*": ["src/middleware/*"],
"@controllers/*": ["src/controllers/*"],
"@routes/*": ["src/routes/*"],
"@models/*": ["src/models/*"],
"@services/*": ["src/services/*"],
"@schemas/*": ["src/schemas/*"],
},
"typeRoots": [
"@types", "./node_modules/@types"
]
},
"exclude": [
"node_modules",
"./*.ts",
"__test__"
],
"include": [
"src/**/*"
]
}
I tried reinstalling node_modules, restarting app a few times.