microsoft / appcenter-cli

Command-line Interface (CLI) for Visual Studio App Center
https://appcenter.ms/
MIT License
582 stars 235 forks source link

when using pnpm, codepush step "react-native bundle" fails #2491

Closed RanolP closed 4 months ago

RanolP commented 6 months ago

Description

We use pnpm for our rn repo since rn 0.73 stabilized symlink support. It works perfectly for our usecases but when I run appcenter codepush, it fails with the message below:

> appcenter codepush release-react [[REDACTED]]

Running "react-native bundle" command:

node node_modules/.bin/react-native bundle --assets-dest [[SHORTENED]]/CodePush --bundle-output [[SHORTENED]]/CodePush/index.android.bundle --dev false --entry-file index.js --platform android
[[REDACTED]]/node_modules/.bin/react-native:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1178:20)
    at Module._compile (node:internal/modules/cjs/loader:1220:27)
    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

Since pnpm generates node_modules/.bin/react-native executable file as bash script for their own node setup, it cannot be executed simply with node. Here's an example of pnpm-generated bin file:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -z "$NODE_PATH" ]; then
  export NODE_PATH="[[REDACTED]]/node_modules/.pnpm/node_modules"
else
  export NODE_PATH="[[REDACTED]]/node_modules/.pnpm/node_modules:$NODE_PATH"
fi
if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../react-native/cli.js" "$@"
else
  exec node  "$basedir/../react-native/cli.js" "$@"
fi

I think it should be executed without the node specification cuz react-native cli also did shebang very well (you can cat node_modules/react-native/cli.js | head -n1 for check). If there's reason to put node, I'd like to suggest that read the first line of the file for shebang check and branching it to care about to execute with node or not.

Repro Steps

  1. Setup a react-native project with pnpm
  2. Run appcenter codepush with proper arguments

Expected behavior

It should work successfully.

Details

  1. Is there a particular beacon/command that you are having trouble with?
    • appcenter codepush
  2. Which version of the App Center CLI are you using?
    • Uses 2.11.0 but upgrade to 3.0.0 haven't fixed the issue
  3. Which OS version did you experience the issue on?
    • macOS 14 Sonoma
  4. What command line/shell are you using?
    • zsh 5.9 (x86_64-apple-darwin23.0)
  5. What version of Node.js and NPM/Yarn are you using?
    • Node v18.15.0, pnpm 8.15.5 (node version seems irrelevant to this issue)
  6. Additionally, you can provide verbose logs of a CLI command by using DEBUG="appcenter-cli:*" before the command, for example, DEBUG="appcenter-cli:*" appcenter apps list. Include the logs here, don't forget to omit any personal/sensitive data.
    • verbose logs aren't useful this time
DordeDimitrijev commented 5 months ago

Hello @RanolP thank you for reaching out. Here is a possible solution for the problem you are facing.

Let me know if this does the trick.

RanolP commented 5 months ago

it works but seems to drop all the advantages from pnpm and use the pnpm as ye olde npm/yarn classic. aren't there alternatives to this?

AlexanderWeigand commented 5 months ago

I am facing the same problem. As described here, the command is working on my local windows machine, just not in my CI pipeline. So I'd rather just keep using it locally than setting node-linker=hoisted, which defeats the purpose of using pnpm altogether and would also require me to apply many other configuration changes to my RN project and monorepo. It would be great, if we could find a way to get codepush to work in a monorepo with a standard pnpm configuration!

DordeDimitrijev commented 5 months ago

Hello @RanolP @AlexanderWeigand, based on what I found out there are still a lot compatibility issues with pnpm and react native. Please try this approach

  1. generate the bundle using react-native bundle command
  2. use general appcenter codepush command as such appcenter codepush release -a <ownerName>/<appName> -c <pathToBundle> -t <targetBinaryVersion> -d <deploymentName>

Take a look at docs for additional information. Please let me know if this solves the issue.

DordeDimitrijev commented 4 months ago

Closing due inactivity.