我正在做一个几年前的项目,我必须再次调试/运行,到目前为止它一直很痛苦。我能够安装大多数依赖项,但除了一次我很幸运,但无法复制这个,我总是无法安装chartjs-node。我使用node v12.18.1和npm 6.14.5以及Visual Studio Code作为终端。
每次我尝试npm i chartjs-node
或npm i in
一般我得到以下内容:
…
c:usersuserdesktopsensqbotreponode_moduleschartjs-nodenode_modulescanvassrccanvas.h(19): fatal error C1083: Datei (Include) kann nicht geöffnet werden: "cairo.h": No such file or dire
ctory (Quelldatei wird kompiliert ..srcCanvasPattern.cc) [C:UsersUserDesktopSensQBotreponode_moduleschartjs-nodenode_modulescanvasbuildcanvas.vcxproj]
c:usersuserdesktopsensqbotreponode_moduleschartjs-nodenode_modulescanvassrccanvas.h(19): fatal error C1083: Datei (Include) kann nicht geöffnet werden: "cairo.h": No such file or dire
ctory (Quelldatei wird kompiliert ..srcCanvasRenderingContext2d.cc) [C:UsersUserDesktopSensQBotreponode_moduleschartjs-nodenode_modulescanvasbuildcanvas.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:Program Filesnodejsnode_modulesnpmnode_modulesnode-gyplibbuild.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:315:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:UsersUserDesktopSensQBotreponode_moduleschartjs-nodenode_modulescanvas
gyp ERR! node -v v12.18.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN The package ava is included as both a dev and production dependency.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modulescaironode_modulesfsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! canvas@1.6.13 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the canvas@1.6.13 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersUserAppDataRoamingnpm-cache_logs2021-08-03T16_49_06_319Z-debug.log
我按照指南安装了像canvas和cairo这样的依赖项,这应该很好,我手动安装了GTK到C:/GTK,我安装了libjpeg, node-gyp是全局安装的:https://github.com/Automattic/node-canvas/wiki/Installation%3A-Windows
并且安装cairo和canvas都很好,我只是不明白为什么我能够一次又一次地安装chartjs-node,不幸的是,我丢失了文件夹,因为我测试了我可以把它复制到一个项目的node_modules中,它会运行。
对不起,如果这个问题太不具体,我只是一个node/npm的初学者,我自己也没有写过这个项目,所以我只是从一个错误到另一个错误,直到它变得更接近运行。请询问您是否需要一个完整的日志或更多的规格。提前谢谢你。
错误中显示"Failed at the canvas@1.6.13 install script."
及"This is probably not a problem with npm. There is likely additional logging output above."
以下
正上方的错误显示"canvas@1.6.13 install:node-gyp rebuild
",所以你应该尝试运行node-gyp rebuild
如果这不起作用,试试这个:
- run:
npm cache clean --force
- delete
node_modules
- delete
packagelock.json
- run:
npm install
最后至少让项目运行起来的是:
npm install chart.js@2.7.*
npm install chartjs-node@^1.7.1 --force
npm install
所以,当有人有一个模块,似乎只是不可能安装,我建议运行npm audit
,这告诉我,chartjs-node也缺少chart.js@2.7.
*,然后我只需要强制安装,我几乎可以肯定,因为我只是忽略了错误,这将导致问题以后,但至少我现在有一个构建尝试!另外,降低node-gyp的版本可能对老项目有所帮助,至少我在这里有这种感觉。