当我尝试使用gatsby-cli构建新项目时,出现错误

时间:2020-05-03 09:54:37

标签: reactjs npm npm-install gatsby

‼ Command failed: C:\projects\my-blazing-fast-site\node_modules\pngquant-bin\vendor\pngquant.exe --version

‼ pngquant pre-build test failed
i compiling from source
× Error: pngquant failed to build, make sure that libpng-dev is installed
at Promise.all.then.arr (C:\projects\my-blazing-fast-site\node_modules\execa\index.js:231:11)
at processTicksAndRejections (internal/process/task_queues.js:86:5)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pngquant-bin@5.0.2 postinstall: node lib/install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pngquant-bin@5.0.2 postinstall 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:\Users\Maciek\AppDa

2 个答案:

答案 0 :(得分:2)

要获取解决方案,请按照以下步骤操作

  1. 删除旧节点模块文件夹, 在安装之前先创建新的Gatsby Project,

    npm install --global windows-build-tools
    
  2. 然后,按照Gatsby文档创建Project,访问https://www.gatsbyjs.org/docs/quick-start/

    npm install -g gatsby-cli
    
    gatsby new gatsby-site
    
    cd gatsby-site
    
    gatsby develop
    
  3. 然后,如果错误如上所示,我们需要在外部安装

    npm install imagemin-pngquant@5.0.1 --save
    
    npm install pngquant-bin@3.1.1 --save
    

答案 1 :(得分:0)

我尝试了各种解决方案,并在安装依赖于pngquant的Sharp插件时遇到了此问题。一种可能的方法是从node_modules中删除Sharp文件夹(或任何其他向您发出警告的插件)。然后插入以下代码。

npm config set ignore-scripts false

重新安装Sharp /任何有问题的插件,希望您可以运行gatsby。到目前为止,在我的机器上一切正常。