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

Creating a Native Module is failing at "Prebuilding the example app" step (MacOS)(Linux) #28189

Open
greynewell opened this issue Apr 12, 2024 · 8 comments
Assignees
Labels
CLI Versioned Expo CLI -- `npx expo start`

Comments

@greynewell
Copy link

Summary

While following the tutorial, I'm getting the following error while running yarn create expo-module x:

✖ Prebuilding the example app
Error: npx expo prebuild --no-install exited with non-zero code: 1
    at ChildProcess.completionListener (/home/ec2-user/.config/yarn/global/node_modules/@expo/spawn-async/build/spawnAsync.js:42:23)
    at Object.onceWrapper (node:events:632:26)
    at ChildProcess.emit (node:events:517:28)
    at maybeClose (node:internal/child_process:1098:16)
    at ChildProcess._handle.onexit (node:internal/child_process:303:5)
    ...
    at spawnAsync (/home/ec2-user/.config/yarn/global/node_modules/@expo/spawn-async/build/spawnAsync.js:7:23)
    at /home/ec2-user/.config/yarn/global/node_modules/create-expo-module/build/createExampleApp.js:129:41
    at newStep (/home/ec2-user/.config/yarn/global/node_modules/create-expo-module/build/utils.js:21:22)
    at prebuildExampleApp (/home/ec2-user/.config/yarn/global/node_modules/create-expo-module/build/createExampleApp.js:128:31)
    at createExampleApp (/home/ec2-user/.config/yarn/global/node_modules/create-expo-module/build/createExampleApp.js:56:11)
    at async Command.main (/home/ec2-user/.config/yarn/global/node_modules/create-expo-module/build/create-expo-module.js:111:13) {
  pid: 3582,
  output: [
    '',
    'npm WARN exec The following package was not found and will be installed: expo@50.0.15\n' +
      'npm WARN deprecated @babel/plugin-proposal-optional-catch-binding@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.\n' +
      'npm WARN deprecated @babel/plugin-proposal-numeric-separator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.\n' +
      'npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.\n' +
      'npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs\n' +
      'npm WARN deprecated @babel/plugin-proposal-logical-assignment-operators@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.\n' +
      'npm WARN deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.\n' +
      'npm WARN deprecated @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.\n' +
      'npm WARN deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.\n' +
      'npm WARN deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.\n' +
      'CommandError: Cannot determine which native SDK version your project uses because the module `expo` is not installed. Please install it with `yarn add expo` and try again.\n' +
      '\n'
  ],
  stdout: '',
  stderr: 'npm WARN exec The following package was not found and will be installed: expo@50.0.15\n' +
    'npm WARN deprecated @babel/plugin-proposal-optional-catch-binding@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.\n' +
    'npm WARN deprecated @babel/plugin-proposal-numeric-separator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.\n' +
    'npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.\n' +
    'npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs\n' +
    'npm WARN deprecated @babel/plugin-proposal-logical-assignment-operators@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead.\n' +
    'npm WARN deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.\n' +
    'npm WARN deprecated @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.\n' +
    'npm WARN deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.\n' +
    'npm WARN deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.\n' +
    'CommandError: Cannot determine which native SDK version your project uses because the module `expo` is not installed. Please install it with `yarn add expo` and try again.\n' +
    '\n',
  status: 1,
  signal: null
}
error Command failed.
Exit code: 1
Command: /home/ec2-user/.yarn/bin/create-expo-module
Arguments: expo-settings
Directory: /home/ec2-user
Output:

info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.

What platform(s) does this occur on?

Android, iOS, Web

SDK Version

50.0.15

Environment

Failing in two environments:

  expo-env-info 1.2.0 environment info:
    System:
      OS: Linux 6.1 Amazon Linux 2023
      Shell: 5.2.15 - /bin/bash
    Binaries:
      Node: 18.20.2 - ~/.volta/tools/image/node/18.20.2/bin/node
      Yarn: 1.22.19 - ~/.volta/tools/image/yarn/4.1.1/bin/yarn
      npm: 10.5.0 - ~/.volta/tools/image/node/18.20.2/bin/npm
    Expo Workflow: managed

and

  expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 14.4
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.12.2 - ~/.volta/tools/image/node/20.12.2/bin/node
      Yarn: 4.0.2 - ~/.volta/tools/image/yarn/4.0.2/bin/yarn
      npm: 10.5.2 - ~/.volta/tools/image/npm/10.5.2/bin/npm
      Watchman: 2024.04.08.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.15.2 - /opt/homebrew/lib/ruby/gems/3.1.0/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 23.4, iOS 17.4, macOS 14.4, tvOS 17.4, visionOS 1.1, watchOS 10.4
    IDEs:
      Xcode: 15.3/15E204a - /usr/bin/xcodebuild

Minimal reproducible example

https://github.com/greynewell/expo-module-failure-example

@greynewell greynewell added CLI Versioned Expo CLI -- `npx expo start` needs validation Issue needs to be validated labels Apr 12, 2024
@expo-bot expo-bot removed the needs validation Issue needs to be validated label Apr 12, 2024
@greynewell
Copy link
Author

I've tried a great deal of variations, including using npx instead of yarn, different versions of both, installing expo-cli globally, uninstalling it globally, adding expo to the example with yarn and attempting to continue with the prebuild.

Although I can get the prebuild to complete by adding the expo package, I still feel like this command should work on either MacOS or Linux - not to mention, the example app does not actually run in the iOS simulator after the prebuild, making me think there are more steps to yarn create expo-module that happen after prebuilding the example that need to be carried out in order to link the Native dependency code from the host package.

Can anyone help me get unstuck? I am attempting to bridge a native iOS SDK into Expo to workaround an issue with matrix-js-sdk support in React Native: https://github.com/greynewell/example-expo-matrix-js-sdk

@greynewell
Copy link
Author

Tried using EXPO_BETA and that also does not work at the moment.

Found this while perusing the source code:

  // Set the native modules dir to the root folder,
  // so that the autolinking can detect and link the module.
  packageJson.expo.autolinking = {
    nativeModulesDir: '..',
  };

When I added the above code snippet to the package.json inside example/ manually, I was able to get the example project running and link the newly generated native module properly.

Let me see if I can create a PR to correct the basic issue so the script will run on the first time.

@greynewell
Copy link
Author

It appears that prebuildExampleApp expects dependencies to be installed in example/ already, because it's passing in a --no-install flag to the "prebuild" command:

await spawnAsync('npx', ['expo', 'prebuild', '--no-install'], {

I think removing this flag will likely fix the error:

npm WARN exec The following package was not found and will be installed: expo@50.0.15\n

@greynewell
Copy link
Author

I was able to fix the issue, test and confirm the fix locally, so I raised a PR: #28191

If we can merge this solution, then the issue will be officially closed.

Can someone else confirm if they can repro the initial behavior?

@Kudo
Copy link
Contributor

Kudo commented Apr 16, 2024

hi there! i think we don't fully support yarn v4 at the moment. when creating the example project with the command internally yarn create expo-app -- x-example --template expo-template-blank-typescript@latest --yes. it will have the following error

✔ Downloaded and extracted project files.
> yarn install
error This project's package.json defines "packageManager": "yarn@4.1.1". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
Something went wrong installing JavaScript dependencies. Check your yarn logs. Continuing to create the app.
Error: yarnpkg exited with non-zero code: 1

removing the file and not pinning yarn v4 should do the trick.

@greynewell
Copy link
Author

greynewell commented Apr 17, 2024

@Kudo it does not. Running in a new folder, using yarn classic (version v1.22.19 as you can see below):

greynewell@grey test % yarn create expo-module x
yarn create v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...

success Installed "create-expo-module@0.6.7" with binaries:
      - create-expo-module
✔ What is the name of the npm package? … x














✔ What is the native module name? … X













✔ How would you describe the module? … My new module
✔ What is the Android package name? … expo.modules.x
✔ What is the name of the package author? … Grey Newell
✔ What is the email address of the author? … g@wdym.chat



✔ What is the URL to the author's GitHub profile? … https://github.com/greynewell


✔ What is the URL for the repository? … https://github.com/greynewell/x

⠙ Downloading module template from npm
⠼ Downloading module template from npm
⠦ Downloading module template from npm
✔ Downloaded module template from npm
✔ Created the module from template files
⠙ Installing module dependencies
✔ Installed module dependencies
✔ Compiled TypeScript files
✔ Initialized the example app
✔ Configured the example app
✖ Prebuilding the example app
Error: npx expo prebuild --no-install exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/greynewell/.config/yarn/global/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 ChildProcess._handle.onexit (node:internal/child_process:305:5)
    ...
    at spawnAsync (/Users/greynewell/.config/yarn/global/node_modules/@expo/spawn-async/build/spawnAsync.js:7:23)
    at /Users/greynewell/.config/yarn/global/node_modules/create-expo-module/build/createExampleApp.js:129:41
    at newStep (/Users/greynewell/.config/yarn/global/node_modules/create-expo-module/build/utils.js:21:22)
    at prebuildExampleApp (/Users/greynewell/.config/yarn/global/node_modules/create-expo-module/build/createExampleApp.js:128:31)
    at createExampleApp (/Users/greynewell/.config/yarn/global/node_modules/create-expo-module/build/createExampleApp.js:56:11)
    at async Command.main (/Users/greynewell/.config/yarn/global/node_modules/create-expo-module/build/create-expo-module.js:111:13) {
  pid: 3605,
  output: [
    '',
    'npm WARN exec The following package was not found and will be installed: expo@50.0.17\n' +
      'CommandError: Cannot determine which native SDK version your project uses because the module `expo` is not installed. Please install it with `yarn add expo` and try again.\n' +
      '\n'
  ],
  stdout: '',
  stderr: 'npm WARN exec The following package was not found and will be installed: expo@50.0.17\n' +
    'CommandError: Cannot determine which native SDK version your project uses because the module `expo` is not installed. Please install it with `yarn add expo` and try again.\n' +
    '\n',
  status: 1,
  signal: null
}
error Command failed.
Exit code: 1
Command: /Users/greynewell/.yarn/bin/create-expo-module
Arguments: x
Directory: /Users/greynewell/test
Output:

info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.

@greynewell
Copy link
Author

@Kudo I want to make sure we're on the same page - the example you are looking at is the result of running yarn create expo-module x with yarn classic to work around the issues with yarn 4.

It is the script that creates the module which is broken, I am not attempting to run any sort of script in the repository, just the basic script itself is not functional.

@byCedric
Copy link
Member

Ah, I think it's this part: https://github.com/greynewell/expo-module-failure-example/blob/main/.yarnrc.yml

React Native, in general, doesn't work with plug-and-play. It violates the fundamentals of how React Native projects are structured using packages containing native code and pointing native code to those files.

I've created a fix to make npx create-expo (not expo-module) to configure this automatically when using yarn v4 (#27699). This hasn't been released yet, which we probably should do soon. With that change, yarn should be configured properly with nodeLinker: node-modules (docs).

For now, one thing you can try @greynewell is doing the last 2 steps manually, while also configure your project to use nodeLinker: node-modules.

  1. $ yarn config set nodeLinker node-modules (configure nodeLinker)
  2. $ yarn install (Installs the node_modules)
  3. $ yarn expo prebuild --no-install (first failing step)
  4. $ npx pod-install / $ cd ios && pod install (run the last step of create-expo-module)

Hope this might help!

@byCedric byCedric self-assigned this Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI Versioned Expo CLI -- `npx expo start`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants