NodeJS 如何使用 puppet 里面的依赖关系?

xuo3flqw  于 2023-01-16  发布在  Node.js
关注(0)|答案(1)|浏览(125)

我正在创建一个依赖生成PDF格式的nestjs,这样做,我使用 puppet 。
当我尝试在dependency中使用puppeteer时,我得到一个错误:

Error: Run `npm install` to download the correct Chromium revision (1056772).

但是当我从项目而不是从依赖项中做的时候就没有错误了。它只发生在我从依赖项中使用 puppet 师的时候,但是它是从同一个项目中启动的。
首先,我在一个nestjs项目中生成了PDF,它工作得很好。
然后我将代码移到服务内的库中,但随后出现了错误。
我尝试运行以下命令来安装chromium

node node_modules/puppeteer/install.js

但没有任何变化,下面是命令的结果:
chrome 已经在C:\用户\格雷格.缓存\ puppet 师\ chrome \win 64 -1069273;正在跳过下载。
我还尝试删除节点模块并重新安装,但没有任何变化。
依赖关系的package.json:

{
  "name": "@gboutte/nestjs-pdf",
  "version": "0.0.3",
  "description": "This package provide a service to render PDF from html string or from handlebars tempaltes for nestjs.",
  "keywords": [
    "nestjs",
    "handlebars",
    "hbs",
    "templates",
    "pdf"
  ],
  "homepage": "https://github.com/gboutte/nestjs-pdf#readme",
  "bugs": {
    "url": "https://github.com/gboutte/nestjs-pdf/issues",
    "email": "gboutte@protonmail.com"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gboutte/nestjs-pdf"
  },
  "main": "dist/index.js",
  "types": "dist/index.d.ts",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "rimraf dist && tsc",
    "prepublish": "npm run build"
  },
  "author": "Grégory Boutte <gboutte@protonmail.com>",
  "license": "MIT",
  "dependencies": {},
  "devDependencies": {
    "@nestjs/common": "^9.1.6",
    "@gboutte/nestjs-hbs": "^0.0.3",
    "@types/node": "^18.11.5",
    "puppeteer": "^19.1.2",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.7",
    "typescript": "^4.8.4"
  },
  "peerDependencies": {
    "@nestjs/common": "^9.1.6",
    "@gboutte/nestjs-hbs": "^0.0.3",
    "@types/node": "^18.11.5",
    "puppeteer": "^19.1.2",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.5.7",
    "typescript": "^4.8.4"
  }
}

以及主项目的package.json

{
  "name": "nestjs-hbs-demo",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "main": "dist/index.js",
  "readmeFilename": "README.md",
  "files": [
    "dist/**/*",
    "*.md"
  ],
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "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": {
    "@gboutte/nestjs-hbs": "file:../nestjs-hbs",
    "@gboutte/nestjs-pdf": "file:../nestjs-pdf",
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/platform-express": "^9.0.0",
    "@nestjs/platform-fastify": "^9.1.6",
    "puppeteer": "^19.4.1",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "28.1.8",
    "@types/node": "^16.0.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "28.1.3",
    "prettier": "^2.3.2",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "28.0.8",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}
zf2sa74q

zf2sa74q1#

我通过更新本地nodejs解决了这个问题,并将两个项目的@types/node依赖项更改为相同。

"@types/node": "^18.0.0",

通过尝试用github而不是本地安装库,我发现就是这个问题。
在使用npm install ../directory-to-my-lib之前,我使用了npm install <url to the github repo>
不同的是,使用github npm给了我一个错误,说两个版本的@types/node是不同的,我不知道为什么我没有这个错误使用其他命令.
现在我修复了版本,它可以与所有安装方法(npm包/ github /local)一起工作。

相关问题