1

因此,当我尝试使用 Docker 运行我的应用程序时,Typescript 会引发编译错误时,我会遇到这个奇怪的错误。当我在我的计算机上本地运行它时,不会发生此错误。

我的 Dockerfile

FROM node:alpine

WORKDIR /app

COPY package.json .
RUN npm install --only=prod
COPY ./ ./

CMD ["npm", "start"]

包.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"
  }
}

错误

这些是 Typescript 抱怨的代码。显然,Typescript 期望“done()”回调有 1 个参数,这是没有意义的。

userSchema.pre('save', async function (done) {
  if (this.isModified('password')) {
    const hashed = await Password.toHash(this.get('password'));
    this.set('password', hashed);
  }
  done();
});
4

0 回答 0