Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on local build Expo EAS with Yarn 4.1.1 #22631

Closed
1 of 4 tasks
guillempuche opened this issue Apr 2, 2024 · 11 comments · Fixed by #26992
Closed
1 of 4 tasks

Error on local build Expo EAS with Yarn 4.1.1 #22631

guillempuche opened this issue Apr 2, 2024 · 11 comments · Fixed by #26992
Assignees
Labels
scope: react-native Issues relating to React Native type: bug

Comments

@guillempuche
Copy link

guillempuche commented Apr 2, 2024

Current Behavior

Run EAS build with Nx EAS Pre Install script with Yarn 4.1 throws an error.

Expected Behavior

Build locally the app on my Android emulator.

GitHub Repo

No response

Steps to Reproduce

  1. Files
    // apps/xiroi-expo/project.json
...
               "build-dev-android": {
			"executor": "@nx/expo:build",
			"options": {
				"platform": "android",
				"profile": "development",
				"local": true,
				"clearCache": false
			}
		},
...

// tools/scripts/eas-build-pre-install.mjs

/*
 * This script is used to patch the '@nx/expo' package to work with EAS Build.
 * It is run as the eas-build-pre-install script in the 'package.json' of expo app.
 * It is executed as 'node tools/scripts/eas-build-pre-install.mjs <workspace root> <project root>'
 * It will copy the dependencies and devDependencies from the workspace package.json to project's package.json.
 * This is needed because EAS Build does the install in project's directory and not workspace's directory.
 */
import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

const [workspaceRoot, projectRoot] = process.argv.slice(2);
if (!workspaceRoot) {
  throw new Error('Missing workspace root');
}
if (!projectRoot) {
  throw new Error('Missing project root');
}
try {
  const workspacePackage = JSON.parse(
    readFileSync(join(workspaceRoot, 'package.json')).toString()
  );
  const projectPackage = JSON.parse(
    readFileSync(join(projectRoot, 'package.json')).toString()
  );
  projectPackage.dependencies = workspacePackage.dependencies;
  projectPackage.devDependencies = workspacePackage.devDependencies;
  writeFileSync(
    join(projectRoot, 'package.json'),
    JSON.stringify(projectPackage, null, 2)
  );
} catch (e) {
  console.error('Error reading package.json file', e);
}
  1. yarn exec nx run xiroi-expo:build-dev-android
  2. I process with interactive dialog
  3. Get error

Nx Report

Node   : 20.11.0
OS     : darwin-arm64
yarn   : 4.1.1

nx                : 18.2.2
@nx/js            : 18.2.2
@nx/jest          : 18.2.2
@nx/linter        : 18.2.2
@nx/eslint        : 18.2.2
@nx/workspace     : 18.2.2
@nx/cypress       : 18.2.2
@nx/devkit        : 18.2.2
@nx/expo          : 18.2.2
@nx/next          : 18.2.2
@nx/react         : 18.2.2
@nx/react-native  : 18.2.2
@nx/storybook     : 18.2.2
@nrwl/tao         : 18.2.2
@nx/vite          : 18.2.2
@nx/web           : 18.2.2
@nx/webpack       : 18.2.2
typescript        : 5.4.3

Failure Logs

✔ Using remote Android credentials (Expo server)
✔ Using Keystore from configuration: Build Credentials sKIJ_f5Qy3 (default)
✔ Compressed project files 2s (4.2 MB)
ANDROID_NDK_HOME environment variable was not specified, continuing build without NDK
[SETUP_WORKINGDIR] Preparing workingdir /var/folders/ys/spt316fs5sxck01gjy40s1rc0000gn/T/eas-build-local-nodejs/5e53c180-8067-49e4-baa6-dc79011017dd
[START_BUILD] Starting build
  "job": {
    "type": "managed",
    "platform": "android",
    "projectRootDirectory": "apps/xiroi-expo",
    "projectArchive": {
      "type": "PATH",
      "path": "/var/folders/ys/spt316fs5sxck01gjy40s1rc0000gn/T/eas-cli-nodejs/6fdcab7d-0cc4-4940-ba1c-9c301f7e0376.tar.gz"
    },
    "builderEnvironment": {},
    "cache": {
      "disabled": false,
      "paths": [],
      "clear": false
    },
    "updates": {},
    "developmentClient": true,
    "buildType": "apk",
    "username": "xiroi",
    "experimental": {},
    "mode": "build",
    "triggeredBy": "EAS_CLI"
  }
[PRE_INSTALL_HOOK] Script 'eas-build-pre-install' is present in package.json, running it...
[PRE_INSTALL_HOOK] Internal Error: ENOENT: no such file or directory, stat '/private/var/folders/ys/spt316fs5sxck01gjy40s1rc0000gn/T/eas-build-local-nodejs/5e53c180-8067-49e4-baa6-dc79011017dd/build/.yarn/releases/yarn-4.1.1.cjs'
[PRE_INSTALL_HOOK] Error: ENOENT: no such file or directory, stat '/private/var/folders/ys/spt316fs5sxck01gjy40s1rc0000gn/T/eas-build-local-nodejs/5e53c180-8067-49e4-baa6-dc79011017dd/build/.yarn/releases/yarn-4.1.1.cjs'
[PRE_INSTALL_HOOK] 
Error: yarn run eas-build-pre-install exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/spawn-async/build/spawnAsync.js:42:23)
    at Object.onceWrapper (node:events:633:26)
    at ChildProcess.emit (node:events:518:28)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:518:28)
    at Pipe.<anonymous> (node:net:337:12)
    ...
    at spawnAsync (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/spawn-async/build/spawnAsync.js:7:23)
    at spawn (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/turtle-spawn/dist/index.js:16:47)
    at runHookIfPresent (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/utils/hooks.js:34:42)
    at async /Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/common/setup.js:48:9
    at async BuildContext.runBuildPhase (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/context.js:98:28)
    at async setupAsync (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/common/setup.js:47:5)
    at async buildAsync (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/builders/android.js:38:5)
    at async runBuilderWithHooksAsync (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/builders/common.js:12:13)
    at async Object.androidBuilder (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/@expo/build-tools/dist/builders/android.js:24:16)
    at async buildAndroidAsync (/Users/guillem/.npm/_npx/df16f1aa38b72159/node_modules/eas-cli-local-build-plugin/dist/android.js:66:12)

Build failed
Unknown error. See logs of the Pre-install hook build phase for more information.
npx exited with non-zero code: 1
    Error: build command failed.

 NX   1



———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target build-dev-android for project xiroi-expo (11s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]

Package Manager Version

yarn 4.1.1

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

The package.json has Yarn configured, check it below. You can also do it running yarn set version berry.

...
  "engines": {
    "node": ">=20"
  },
  "packageManager": "yarn@4.1.1"
...

// .yarnrc.yml

nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.1.1.cjs

Other version of packages:

  • expo 50.0.14
  • eas-cli 7.6.2

I read https://docs.expo.dev/build-reference/npm-cache-with-yarn/, but I don't know what to do. According to ChatGTP:

The Expo guide script focuses on optimizing package installation by leveraging EAS's npm cache. In contrast, your script focuses on dependency management within a monorepo setup, ensuring that project dependencies are correctly set up for the build.

@guillempuche guillempuche changed the title Error on when making a local build in Expo EAS Pre Install Hook with Yarn 4.1.1 Error on when local build Expo EAS with Yarn 4.1.1 Apr 2, 2024
@guillempuche
Copy link
Author

I haven't check yet the post install script from Nx example tools/scritps/eas-build-post-install.mjs.

/**
 * This script is used to patch the '@nx/expo' package to work with EAS Build.
 * It is run as a eas-build-post-install script in the 'package.json' of expo app.
 * It is executed as 'node tools/scripts/eas-build-post-install.mjs <workspace root> <project root>'
 * It will create a symlink from the project's node_modules to the workspace's node_modules.
 */

import { existsSync, symlink } from 'node:fs'
import { join } from 'node:path'

const [workspaceRoot, projectRoot] = process.argv.slice(2)

if (existsSync(join(workspaceRoot, 'node_modules'))) {
	console.log('Symlink already exists')
	process.exit(0)
}

symlink(
	join(projectRoot, 'node_modules'),
	join(workspaceRoot, 'node_modules'),
	'dir',
	err => {
		if (err) console.log(err)
		else {
			console.log('Symlink created')
		}
	},
)

@guillempuche guillempuche changed the title Error on when local build Expo EAS with Yarn 4.1.1 Error on local build Expo EAS with Yarn 4.1.1 Apr 3, 2024
@FrozenPandaz FrozenPandaz added the scope: react-native Issues relating to React Native label Apr 5, 2024
@xiongemi
Copy link
Collaborator

xiongemi commented Apr 8, 2024

i tried to build with eas locally. here are what i did:

@guillempuche
Copy link
Author

guillempuche commented Apr 18, 2024

@xiongemi, do you have a solution for the latest versions?

@guillempuche
Copy link
Author

guillempuche commented May 3, 2024

React Native 0.74 https://reactnative.dev/blog/2024/04/22/release-0.74 has Yarn 3 as the default package manager for new projects. Not npm.

It's a good moment to handle EAS build v7 and v8 in Expo https://github.com/expo/eas-cli/releases with Yarn v4. 😉

@guillempuche
Copy link
Author

Expo team is recommending to use build development. A screenshot from one of its team members.

imatge

@xiongemi
Copy link
Collaborator

xiongemi commented Jul 19, 2024

the quickest workaround would be: go the app and run npm run eas-build-pre-install then delete this script from the package.json's scripts.
now when you run the local build, it should work with yarn 4
i am working on a pr to do a proper fix for this

FrozenPandaz pushed a commit that referenced this issue Sep 3, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #22631

(cherry picked from commit 81acded)
@xiongemi
Copy link
Collaborator

xiongemi commented Sep 4, 2024

another quick fix would be in package.json, add your app and library to workspaces, something like:

  "workspaces": [
    "apps/*",
    "libs/*"
  ],

@guillempuche
Copy link
Author

It didn't work.

@xiongemi
Copy link
Collaborator

xiongemi commented Sep 4, 2024

It didn't work.

what error are you getting?

@guillempuche
Copy link
Author

guillempuche commented Sep 4, 2024

No idea anymore. I stopped using Nx for my monorepos with Expo. I experienced too many errors (I opened issues, but not really solved or take months).

There's a need for Nx with RN (people starring https://github.com/guillempuche/nx-expo-next-tamagui), but the community doesn't push for RN + Nx (just read new PR or issues in Nx)

I'm using straight Yarn for my monorepo and some Turborepo.

@vaagnavanesyan
Copy link

@guillempuche same here. I've used Nx + Expo for a year, and it was a year of struggling with bugs and errors. Now I've ended up with plain Yarn 4 Workspaces and kept Nx only as a task runner and graph builder (to determine what is affected).

Nx may be good for library-oriented monorepos, but I found it inappropriate for application-centric monorepos with web, API, or mobile apps. It's sad that I wasted a year to figure that out because the official docs describe a lot of plugins and executors, which are nothing more than built-in workarounds for Nx-based problems like path resolving.

When using Nx, you get caught in vendor lock-in, which is probably not what you'd want.

It's sad that Nx is the most mentioned tool for monorepos, but in reality, you end up struggling with a bunch of errors. It's definitely not what a production-ready tool should be.

For additional context, I used Nx in a monorepo with TS libraries, web and mobile applications, and a NestJS backend. Now I've switched to Yarn Workspaces, migrated the web project to Vite, and everything works like a charm. Most importantly, it all works predictably.

ZackDeRose pushed a commit to ZackDeRose/nx that referenced this issue Sep 6, 2024
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes nrwl#22631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: react-native Issues relating to React Native type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants