Render部署NestJS项目遇TS2307:找不到class-validator模块
Render平台部署NestJS项目编译报错:无法找到class-validator模块
我在Render平台部署的项目编译失败,报错信息如下:
src/auth/dto/create-auth.dto.ts:6:8 - error TS2307: Cannot find module 'class-validator' or its corresponding type declarations.
我尝试了以下几种解决方案,但均无效:
- 针对TS2307错误查找class-validator模块的常规修复方案
- 处理class-validator作为peer依赖却被强制要求的问题
- 修复npm的ELIFECYCLE错误
唯一能完成部署的方式是执行npm run build --force,但项目启动后仍会报错,编译阶段的问题始终存在。
当前配置详情
- 托管平台:
render - 构建命令:
npm; npm i --save class-validator class-transformer; npm link webpack; npm run build
tsconfig.json
{ "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "es2017", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "incremental": true, "skipLibCheck": true, "strictNullChecks": false, "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": false, "moduleResolution": "Node" } }
package.json
{ "name": "chat", "version": "0.0.1", "description": "", "author": "", "private": true, "license": "UNLICENSED", "scripts": { "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { "@nestjs/class-validator": "^0.13.1", "@nestjs/common": "^9.0.0", "@nestjs/config": "^3.0.0", "@nestjs/core": "^9.0.0", "@nestjs/mapped-types": "^2.0.2", "@nestjs/platform-express": "^9.0.0", "@nestjs/platform-socket.io": "^9.4.0", "@nestjs/typeorm": "^10.0.0", "@nestjs/websockets": "^9.4.0", "@types/bcrypt": "^5.0.0", "@types/cookie-parser": "^1.4.3", "@types/jsonwebtoken": "^9.0.2", "@types/validator": "^13.7.17", "bcrypt": "^5.1.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "cookie-parser": "^1.4.6", "dotenv": "^16.3.1", "hash": "^0.2.1", "jsonwebtoken": "^9.0.0", "nestjs-yup": "^1.0.13", "pg": "^8.11.1", "reflect-metadata": "^0.1.13", "rxjs": "^7.2.0", "socket.io": "^4.7.0", "typeorm": "^0.3.17" }, "devDependencies": { "@nestjs/cli": "^9.0.0", "@nestjs/schematics": "^9.0.0", "@nestjs/testing": "^9.0.0", "@types/express": "^4.17.13", "@types/jest": "29.5.1", "@types/node": "^18.16.12", "@types/supertest": "^2.0.11", "@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/parser": "^5.61.0", "eslint": "^8.0.1", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", "jest": "29.5.0", "source-map-support": "^0.5.20", "supertest": "^6.1.3", "ts-jest": "29.1.0", "ts-loader": "^9.2.3", "ts-node": "^10.0.0", "tsconfig-paths": "4.2.0", "typescript": "^5.0.0" }, "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".*\\.spec\\.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, "collectCoverageFrom": [ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", "testEnvironment": "node" } }
内容的提问来源于stack exchange,提问作者Thrackerzod
相关产品推荐
相关产品推荐

