So I have this weird error when Typescript would throw a Compilation Error when I try to to run my app using Docker. This error does not happen when I run it locally on my computer.
My Dockerfile
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install --only=prod
COPY ./ ./
CMD ["npm", "start"]
Package.json
{
"name": "auth",
"version": "1.0.0",
"description": "Authorization Service for Ticketting",
"main": "index.js",
"type": "module",
"scripts": {
"start": "ts-node-dev --no-deps --respawn --poll --interval 1000 src/index.ts",
"test": "jest --watchAll --no-cache"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"setupFilesAfterEnv": [
"./src/test/setup.ts"
]
},
"author": "Nam Nguyen",
"license": "ISC",
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/supertest": "^2.0.10",
"jest": "^26.6.3",
"mongodb-memory-server": "^6.9.2",
"supertest": "^6.0.1",
"ts-jest": "^26.4.4"
},
"dependencies": {
"@nnticketting/common": "^1.0.5",
"@types/cookie-session": "^2.0.41",
"@types/cors": "^2.8.8",
"@types/express": "^4.17.8",
"@types/jsonwebtoken": "^8.5.0",
"@types/mongoose": "^5.10.0",
"cookie-session": "^1.4.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"express-validator": "^6.6.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.10.13",
"ts-node": "^9.1.0",
"ts-node-dev": "^1.0.0",
"typescript": "^4.1.2"
}
}
And these are the codes that Typescript is complaining about. Apparently Typescript is expecting 1 argument for the "done()" callback which makes no sense.
userSchema.pre('save', async function (done) {
if (this.isModified('password')) {
const hashed = await Password.toHash(this.get('password'));
this.set('password', hashed);
}
done();
});