无法生成资源nestjs:typeScript

Usm*_*man 4 npm typescript yarnpkg nestjs

我收到此错误:

\n
\n
TypeError: Cannot read property \'properties\' of undefined\n\nFailed to execute command: \nnode @nestjs/schematics:resource --name=post --no-dry-run --language="ts" --sourceRoot="src" --spec\n
Run Code Online (Sandbox Code Playgroud)\n
\n

到目前为止,我\xe2\x80\x99已经尝试过:

\n
npm i -g @nestjs/schematics    \n
Run Code Online (Sandbox Code Playgroud)\n

\n
npm install --save-dev webpack-cli@3.1.1   \n
Run Code Online (Sandbox Code Playgroud)\n

但他们也没有奏效。

\n

使用 Nest g 资源创建新资源时出现问题

\n

包.json

\n
{\n  "name": "nestjs",\n  "version": "0.0.1",\n  "description": "",\n  "author": "",\n  "private": true,\n  "license": "UNLICENSED",\n  "scripts": {\n    "prebuild": "rimraf dist",\n    "build": "nest build",\n    "format": "prettier --write \\"src/**/*.ts\\" \\"test/**/*.ts\\"",\n    "start": "nest start",\n    "start:dev": "nest start --watch",\n    "start:debug": "nest start --debug --watch",\n    "start:prod": "node dist/main",\n    "lint": "eslint \\"{src,apps,libs,test}/**/*.ts\\" --fix",\n    "test": "jest",\n    "test:watch": "jest --watch",\n    "test:cov": "jest --coverage",\n    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",\n    "test:e2e": "jest --config ./test/jest-e2e.json"\n  },\n  "dependencies": {\n    "@hapi/joi": "^17.1.1",\n    "@nestjs/common": "^8.0.0",\n    "@nestjs/config": "^2.0.0",\n    "@nestjs/core": "^8.0.0",\n    "@nestjs/jwt": "^8.0.0",\n    "@nestjs/mapped-types": "*",\n    "@nestjs/passport": "^8.2.1",\n    "@nestjs/platform-express": "^8.0.0",\n    "@nestjs/typeorm": "^8.0.3",\n    "@types/bcrypt": "^5.0.0",\n    "@types/cookie-parser": "^1.4.2",\n    "@types/hapi__joi": "^17.1.8",\n    "@types/passport-jwt": "^3.0.6",\n    "@types/passport-local": "^1.0.34",\n    "bcrypt": "^5.0.1",\n    "cookie-parser": "^1.4.6",\n    "passport": "^0.5.2",\n    "passport-jwt": "^4.0.0",\n    "passport-local": "^1.0.0",\n    "pg": "^8.7.3",\n    "reflect-metadata": "^0.1.13",\n    "rimraf": "^3.0.2",\n    "rxjs": "^7.2.0",\n    "typeorm": "^0.2.45"\n  },\n  "devDependencies": {\n    "@nestjs/cli": "^8.0.0",\n    "@nestjs/schematics": "^8.0.0",\n    "@nestjs/testing": "^8.0.0",\n    "@types/express": "^4.17.13",\n    "@types/jest": "27.4.1",\n    "@types/node": "^16.0.0",\n    "@types/supertest": "^2.0.11",\n    "@typescript-eslint/eslint-plugin": "^5.0.0",\n    "@typescript-eslint/parser": "^5.0.0",\n    "eslint": "^8.0.1",\n    "eslint-config-prettier": "^8.3.0",\n    "eslint-plugin-prettier": "^4.0.0",\n    "jest": "^27.2.5",\n    "prettier": "^2.3.2",\n    "source-map-support": "^0.5.20",\n    "supertest": "^6.1.3",\n    "ts-jest": "^27.0.3",\n    "ts-loader": "^9.2.3",\n    "ts-node": "^10.0.0",\n    "tsconfig-paths": "^3.10.1",\n    "typescript": "^4.3.5"\n  },\n  "jest": {\n    "moduleFileExtensions": [\n      "js",\n      "json",\n      "ts"\n    ],\n    "rootDir": "src",\n    "testRegex": ".*\\\\.spec\\\\.ts$",\n    "transform": {\n      "^.+\\\\.(t|j)s$": "ts-jest"\n    },\n    "collectCoverageFrom": [\n      "**/*.(t|j)s"\n    ],\n    "coverageDirectory": "../coverage",\n    "testEnvironment": "node"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

ts配置

\n
{\n  "compilerOptions": {\n    "module": "commonjs",\n    "declaration": true,\n    "removeComments": true,\n    "emitDecoratorMetadata": true,\n    "experimentalDecorators": true,\n    "allowSyntheticDefaultImports": true,\n    "target": "es2017",\n    "sourceMap": true,\n    "outDir": "./dist",\n    "baseUrl": "./",\n    "incremental": true,\n    "skipLibCheck": true,\n    "strictNullChecks": true,\n    "noImplicitAny": false,\n    "strictBindCallApply": false,\n    "forceConsistentCasingInFileNames": false,\n    "noFallthroughCasesInSwitch": false\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

编辑:我还尝试了以下方法,但没有\xe2\x80\x99工作:

\n
npx nest g resource post\n
Run Code Online (Sandbox Code Playgroud)\n

小智 12

我有类似的问题。就我而言,我的全局和本地 Nest cli 版本不同步。我跑了

npm  i -g @nestjs/cli
Run Code Online (Sandbox Code Playgroud)

现在一切正常


Usm*_*man 5

实际上我的项目没有更新。我还更新了一些依赖项,但不是全部。因此它不起作用。

所以我用这个更新项目

nest update -f -t latest 
Run Code Online (Sandbox Code Playgroud)

或者

yarn upgrade-interactive --latest
Run Code Online (Sandbox Code Playgroud)

安装后

yarn global add @nestjs/schematics
Run Code Online (Sandbox Code Playgroud)

现在一切正常