expo / expo

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
https://docs.expo.dev
MIT License
34.21k stars 5.47k forks source link

Can not initialize a new module (exited with non-zero code) #31459

Open yaroslavert opened 1 month ago

yaroslavert commented 1 month ago

Summary

I started discover how to build native module. https://docs.expo.dev/modules/native-module-tutorial/#1-initialize-a-new-module

I runed command npx create-expo-module expo-settings But i can not install npm dependecies

What platform(s) does this occur on?

No response

SDK Version

51.0.32

Environment

expo-env-info 1.2.0 environment info: System: OS: macOS 14.5 Shell: 5.9 - /bin/zsh Binaries: Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node Yarn: 3.6.4 - /opt/homebrew/bin/yarn npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm Watchman: 2024.08.19.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.15.2 - /Users/yaroslavert/.rvm/gems/ruby-3.3.4/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.4, iOS 17.4, macOS 14.4, tvOS 17.4, visionOS 1.1, watchOS 10.4 Android SDK: API Levels: 29, 30, 33, 34 Build Tools: 30.0.3, 33.0.1, 34.0.0 System Images: android-29 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-34 | Google APIs ARM 64 v8a IDEs: Android Studio: 2023.2 AI-232.10300.40.2321.11567975 Xcode: 15.3/15E204a - /usr/bin/xcodebuild

Minimal reproducible example

I can not share link for repo becase can not install modules.

Step to reproduce

npx create-expo-module expo-settings

✖ Installing module dependencies Error: npm install exited with non-zero code: 1 at ChildProcess.completionListener (/Users/yaroslavert/.npm/_npx/62900f925a4b91dc/node_modules/@expo/spawn-async/build/spawnAsync.js:42:23) at Object.onceWrapper (node:events:629:26) at ChildProcess.emit (node:events:514:28) at maybeClose (node:internal/child_process:1105:16) at ChildProcess._handle.onexit (node:internal/child_process:305:5) ... at spawnAsync (/Users/yaroslavert/.npm/_npx/62900f925a4b91dc/node_modules/@expo/spawn-async/build/spawnAsync.js:7:23) at installDependencies (/Users/yaroslavert/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/packageManager.js:9:37) at /Users/yaroslavert/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/create-expo-module.js:86:60 at newStep (/Users/yaroslavert/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/utils.js:21:22) at Command.main (/Users/yaroslavert/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/create-expo-module.js:85:35) { pid: 53646, output: [ '', '' ], stdout: '', stderr: '', status: 1, signal: null }

yaroslavert commented 1 month ago

I found reason.

/expo-module-scripts/bin/npx

#!/usr/bin/env bash

# shellcheck disable=SC2154
if [[ ! "$npm_config_user_agent" =~ yarn ]] && [ -x "$(command -v yarn)" ]; then
  yarn exec -- npx "$@"
else
  npx "$@"
fi

In my system i have both package manager yarn and npm. You script use yarn by default it's mean yarn has move priority

Unfortunately for yarn was not generated yarn.lock file and yarn package manager can not start to install deps

I disabled yarn and now it's work.

nullatnothing commented 1 month ago

Same issue:

nvm: 0.40.1 node: 20.17.0 yarn: 4.4.1 npm: 10.8.2

Command:

npx create-expo-module expo-settings

Then:

Error: npm install exited with non-zero code: 1 at ChildProcess.completionListener (/Users/user/.npm/_npx/62900f925a4b91dc/node_modules/@expo/spawn-async/build/spawnAsync.js:42:23) at Object.onceWrapper (node:events:634:26) at ChildProcess.emit (node:events:519:28) at maybeClose (node:internal/child_process:1105:16) at ChildProcess._handle.onexit (node:internal/child_process:305:5) ... at spawnAsync (/Users/user/.npm/_npx/62900f925a4b91dc/node_modules/@expo/spawn-async/build/spawnAsync.js:7:23) at installDependencies (/Users/user/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/packageManager.js:9:37) at /Users/user/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/create-expo-module.js:86:60 at newStep (/Users/user/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/utils.js:21:22) at Command.main (/Users/user/.npm/_npx/62900f925a4b91dc/node_modules/create-expo-module/build/create-expo-module.js:85:35) { pid: 3996, output: [ '', '' ], stdout: '', stderr: '', status: 1, signal: null }

nullatnothing commented 1 month ago

WORKAROUND

I followed this steps to get the module project running:

  1. npx create-expo-module expo-settings
  2. crash happens
  3. open the file path/to/your/projects/expo-settings/node_modules/expo-module-scripts/bin/npx with text editor
  4. change file content to:
#!/usr/bin/env bash

# Runs `npx` through Yarn if necessary so that the environment variables are set up similarly across
# Yarn and npm.

# shellcheck disable=SC2154
npx "$@"
  1. rerun npx create-expo-module expo-settings
  2. confirm with yes the question: The target directory ... is not empty, do you want to continue anyway?
  3. module project created
chanphiromsok commented 5 days ago

WORKAROUND

I followed this steps to get the module project running:

  1. npx create-expo-module expo-settings
  2. crash happens
  3. open the file path/to/your/projects/expo-settings/node_modules/expo-module-scripts/bin/npx with text editor
  4. change file content to:
#!/usr/bin/env bash

# Runs `npx` through Yarn if necessary so that the environment variables are set up similarly across
# Yarn and npm.

# shellcheck disable=SC2154
npx "$@"
  1. rerun npx create-expo-module expo-settings
  2. confirm with yes the question: The target directory ... is not empty, do you want to continue anyway?
  3. module project created

work for me