这种类型的错误出现了:找不到模块“sharp”。

6
Error: Cannot find module 'sharp'
  Require stack:
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby-plugin-manifest\safe-sharp.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby-plugin-manifest\gatsby-node.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\bootstrap\resolve-module-exports.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\bootstrap\load-plugins\validate.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\bootstrap\load-plugins\load.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\bootstrap\load-plugins\index.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\bootstrap\index.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\commands\develop.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby-cli\lib\create-cli.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby-cli\lib\index.js
  - D:\Marketing\sbj-react\suburban\node_modules\gatsby\dist\bin\gatsby.js

1) npm install:安装项目所需的依赖包。

2) 如果需要权限,可以使用 npm install --unsafe-perm 进行安装。

3) npm start:启动项目。

4) npm install sharp:安装 Sharp 库。

如果还是存在相同的问题,请解决我的问题。

这是我的 package.json 文件。

{
  "name": "Ashish",
  "description": "Ashish Group Project",
  "version": "1.0.0",
  "author": "AshishBhangade <ashishbhangade@gmail.com>",
  "dependencies": {
    "axios": "^0.18.0",
    "babel-plugin-styled-components": "^1.10.0",
    "base-64": "^0.1.0",
    "bcryptjs": "^2.4.3",
    "bootstrap": "^4.1.3",
    "gatsby": "^2.0.53",
    "gatsby-background-image": "^0.9.11",
    "gatsby-graphiql-explorer": "^0.2.29",
    "gatsby-image": "^2.0.20",
    "gatsby-plugin-compression": "0.0.1",
    "gatsby-plugin-compression-v2": "^0.1.0",
    "gatsby-plugin-drift": "^1.0.0",
    "gatsby-plugin-facebook-analytics": "^2.0.2",
    "gatsby-plugin-facebook-pixel": "^1.0.3",
    "gatsby-plugin-facebook-sdk": "^1.0.6",
    "gatsby-plugin-google-analytics": "^2.0.9",
    "gatsby-plugin-google-gtag": "^1.0.8",
    "gatsby-plugin-google-tagmanager": "^2.0.7",
    "gatsby-plugin-hotjar": "^1.0.1",
    "gatsby-plugin-manifest": "^2.0.9",
    "gatsby-plugin-netlify": "^2.0.6",
    "gatsby-plugin-offline": "^2.0.21",
    "gatsby-plugin-react-helmet": "^3.0.2",
    "gatsby-plugin-robots-txt": "^1.4.0",
    "gatsby-plugin-sass": "^2.0.5",
    "gatsby-plugin-sentry": "^1.0.0",
    "gatsby-plugin-sharp": "^2.0.12",
    "gatsby-plugin-sitemap": "^2.0.4",
    "gatsby-plugin-styled-components": "^3.0.4",
    "gatsby-plugin-zopfli": "^1.0.2",
    "gatsby-source-apiserver": "^2.1.4",
    "gatsby-source-filesystem": "^2.0.8",
    "gatsby-transformer-sharp": "^2.1.8",
    "jquery": "^3.3.1",
    "logrocket": "^1.0.6",
    "logrocket-react": "^4.0.1",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.23",
    "node-sass": "^4.10.0",
    "perm": "^1.0.0",
    "react": "^16.6.3",
    "react-bootstrap": "^0.32.4",
    "react-bootstrap-time-picker": "^1.0.3",
    "react-datepicker": "^2.0.0",
    "react-device-detect": "^1.11.14",
    "react-dom": "^16.6.3",
    "react-ga": "^2.5.6",
    "react-helmet": "^5.2.0",
    "react-input-mask": "^2.0.4",
    "react-number-format": "^4.0.6",
    "react-otp-input": "^0.3.1",
    "react-phone-input-2": "^2.11.0",
    "react-places-autocomplete": "^7.2.1",
    "react-popper": "^1.3.2",
    "react-scroll": "^1.7.12",
    "react-select": "^3.0.8",
    "react-slick": "^0.23.2",
    "reactstrap": "^6.5.0",
    "slick-carousel": "^1.8.1",
    "socket.io-client": "^2.2.0",
    "styled-components": "^4.1.3",
    "universal-cookie": "^3.0.7"
  }
}

嗨,@Ashish。你能提供一下package.json文件吗?Node和npm的版本是多少? - Surya
尝试以下组合:1. npm config set ignore-scripts false 2. rm -rf node_modules 3. npm install - hackape
我已经完成了所有步骤超过3次,但仍然无法工作。 - Ashish Bhangade
package.json格式化以便易读。 - Dave Newton
npm安装gatsby-transformer-sharp gatsby-plugin-sharp - Rohan Sharma
显示剩余2条评论
3个回答

4

我也遇到了同样的问题,并通过

npm install sharp

解决了。


2

我在 Mac 上遇到了相同的错误,这个方法解决了我的问题。

基本上:

  • 删除 node_modules 文件夹
  • xcode-select --install
  • 关闭并重新打开终端
  • yarn install(我认为也可以使用 npm install

感谢 @LemLordjeKo - Artur Carvalho

-1
  1. npm rebuild --verbose sharp

这个单行命令帮了我很多,简直是魔法。


你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接