找不到全局sharp-cli包使用的sharp实例

问题描述 投票:0回答:2

当尝试运行 Web 版 Expo 时,在我的应用程序文件夹的根目录中创建名为

webpack.config.js
的文件后,出现错误“无法找到全局 Sharp-cli 包使用的 Sharp 实例”。文件的内容可以像默认的 expo 实现一样简单,但仍然失败:

module.exports = async function(env, argv) {
    const loadDefaultConfigAsync = require('@expo/webpack-config');
    return await loadDefaultConfigAsync(env, argv);
};

节点版本:v16.3.1

NPM版本:v8.1.2

{
  "name": "foo",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^12.0.0",
    "@expo/webpack-config": "^0.16.11",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/native-stack": "^6.1.0",
    "expo": "~43.0.2",
    "expo-asset": "~8.4.3",
    "expo-constants": "~12.1.3",
    "expo-font": "~10.0.3",
    "expo-linking": "~2.4.2",
    "expo-splash-screen": "~0.13.5",
    "expo-status-bar": "~1.1.0",
    "expo-web-browser": "~10.0.3",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.8.0",
    "react-native-web": "0.17.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.64.12",
    "jest-expo": "~43.0.0",
    "typescript": "~4.3.5"
  },
  "private": true
}
node.js webpack expo sharp
2个回答
17
投票

经过一番网上搜索后,我空手而归,找到了一个有效的简单解决方案。我设法通过将

sharp-cli
安装为本地依赖项并使用以下命令将其保存到
package.json
来解决此问题:

npm install --save-dev sharp-cli

0
投票

在 SDK 51 开发版本上进行测试:

使用

--save-dev
解决了该问题,但 EAS 构建失败。我尝试使用
2.1.0
在全球安装版本
npm install -g sharp-cli@^2.1.0
,并且成功了。

© www.soinside.com 2019 - 2024. All rights reserved.