EAS 构建生命周期预安装挂钩在 eas 构建期间失败

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

我正在尝试通过 eas 构建和展示应用程序,但它失败了,并在

eas-build-pre-install
钩子上出现“权限被拒绝”错误。我设置了一个专门为 Android 版本安装 pnpm 的脚本。这是我位于
scripts/eas-pre-install
的预安装脚本:

#!/bin/bash

if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
  npm install -g [email protected]
  pnpm --version
fi

在我的 package.json 中,我定义了 eas-build-pre-install 脚本,如下所示:

"scripts": {
  "eas-build-pre-install": "./scripts/eas-pre-install"
}

这是构建失败时得到的错误日志:

Script 'eas-build-pre-install' is present in package.json, running it...

> [email protected] eas-build-pre-install /home/expo/workingdir/build

> ./scripts/eas-pre-install

sh: 1: ./scripts/eas-pre-install: Permission denied

ELIFECYCLE  Command failed with exit code 126.

WARN   Local package.json exists, but node_modules missing, did you mean to install?

pnpm run eas-build-pre-install exited with non-zero code: 1
react-native expo eas
2个回答
1
投票

确保预安装的脚本有执行权限。您可以使用以下命令授予执行权限:

chmod +x pre-install

运行此命令后,尝试再次执行脚本。


0
投票

问题在于 Windows 处理

bash
.sh
文件的方式。我最近在处理一个博览会项目时遇到了同样的错误,我需要从 MacOS 切换到 Windows。由于权限错误,预构建突然停止工作,如果您使用 Windows,您应该采取以下措施来避免这种情况:

1. Bash 到节点

将您的代码从 bash 转换为 Javascript(Node)等效项,并使用

.js
扩展名保存,在您的情况下它将是:

#!/usr/bin/env node

const { execSync } = require('child_process');

// Check if the platform is MacOS if it darwin then the build is iOS
if (process.platform !== 'darwin') {
    console.log("=====> Not an Android build, skipping pnpm installation");
} else {
console.log("=====> Installing [email protected] globally");

    try {
        // Install pnpm globally
        execSync('npm install -g [email protected]', { stdio: 'inherit' });

        console.log("pnpm installation complete.");
    } catch (error) {
        console.error("Error during pnpm installation:", error.message);
        process.exit(1); // Exit with a non-zero status if the command fails
    }
}

*

darwin
标识 macOS,因为 iOS 构建是在 MacOS 上生成的,这是为了确保
process.platform
中的其他所有内容都被视为 android 构建过程

2.更新
Package.json

更新 `package.json 以将挂钩作为节点脚本执行,如下所示:

"scripts": {
  "eas-build-pre-install": "node ./scripts/eas-pre-install.js"
}

这将确保挂钩保持平台独立性,并且无论您使用的是 Windows、Linux 还是 MacOS,都可以准确执行。

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