Is it possible to create files with NodeJS during EAS Builds?

My setup:

"amazon-cognito-identity-js": "^6.3.13",
"aws-amplify": "^5.3.18",
"aws-amplify-react-native": "^7.0.8",
"expo": "~51.0.11",
"react-native": "0.74.2",

I have a React Native with Expo 51 project and I’m trying to “generate” my aws-exports.js file dynamically during my builds.

I’ve also created some EAS Secrets with my aws-exports.js file encoded in BASE64.

In order to have more flexibility in my builds I’ve overwriten the default eas-build-pre-install hook, so I could run some custom scripts in order to generate my file.

This is working as spected, the aws-exports.js file is created and handleEncodedFile is executed

"eas-build-pre-install": "touch ./src/aws-exports.js && node ./src/scripts/handleEncodedFile.scripts.js",

And here is my handleEncodedFile script:

const fs = require("node:fs");

function createAwsExports() {
  // defaults ENV VARs from EAS
  const buildProfile = process.env.EAS_BUILD_PROFILE;
  const workingDir = process.env.EAS_BUILD_WORKINGDIR;

  try {
    console.info("Using EAS Build Profile: ", buildProfile);
    console.info("Running from DIR: ", workingDir);

    let handleDecodedSecret = null;

    switch (buildProfile) {
      case "development":
        const expoDevSecret = process.env.AWS_EXPORTS_DEV;
        handleDecodedSecret = Buffer.from(expoDevSecret, "base64").toString();
        break;
      case "production":
        const expoPrdSecret = process.env.AWS_EXPORTS_PRD;
        handleDecodedSecret = Buffer.from(expoPrdSecret, "base64").toString();
        break;
      default:
        throw new Error("Unknown build profile: ", buildProfile);
    }

    if (!handleDecodedSecret) {
      throw new Error(
        '"handleDecodedSecret" is NULL. This should never happen'
      );
    }

    // returns TRUE
    console.log(
      'Does "src/aws-exports.js" exists? ',
      fs.existsSync(`${workingDir}/src/aws-exports.js`)
    );

    // Execution stops here
    fs.writeFile(`${workingDir}/src/aws-exports.js`, handleDecodedSecret);
  } catch (error) {
    throw new Error('Error while creating "aws-exports.js": ', error);
  }
}

createAwsExports();

And this is the error I’m getting from Expo Dashboard (not very helpful tbh)

Script 'eas-build-pre-install' is present in package.json, running it...
Fri, 07 Jun 2024 02:04:58 GMT

> <my-app>@1.0.0 eas-build-pre-install

> touch ./src/aws-exports.js && node ./src/scripts/handleEncodedFile.scripts.js

Using EAS Build Profile:  development

Running from DIR:  /home/expo/workingdir/build

Does "src/aws-exports.js" exists?  true

/home/expo/workingdir/build/src/scripts/handleEncodedFile.scripts.js:46

    throw new Error('Error while creating "aws-exports.js": ', error);

          ^

Error: Error while creating "aws-exports.js": 

    at createAwsExports (/home/expo/workingdir/build/src/scripts/handleEncodedFile.scripts.js:46:11)

    at Object.<anonymous> (/home/expo/workingdir/build/src/scripts/handleEncodedFile.scripts.js:50:1)

    at Module._compile (node:internal/modules/cjs/loader:1256:14)

    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

    at Module.load (node:internal/modules/cjs/loader:1119:32)

    at Module._load (node:internal/modules/cjs/loader:960:12)

    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)

    at node:internal/main/run_main_module:23:47

Node.js v18.18.0

npm run eas-build-pre-install exited with non-zero code: 1

The scripts above should:

  1. Create an empty aws-exports.js in the expo workingdir /home/expo/workingdir/build/src
  2. Validate which eas profile the build is running on and use the respective EAS Secret

In previous projects I’m using the following script in my package.json

// I always need to alter manually from AWS_EXPORTS_PRD to AWS_EXPORTS_DEV depending on the build
"eas-build-pre-install": "echo $AWS_EXPORTS_PRD | base64 -d -i > ./src/aws-exports.js"

It doesn’t break, but also doesn’t work. For some reason the only way I’ve got it working was removing it from the .gitignore, which I’m sick of doing.

Thansk for the help in advance!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật