react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

Deployment and hermes builds are failing in monorepo (Lerna, Yarn workspaces)

Open tad3j opened this issue 4 years ago • 2 comments

Steps to Reproduce

  1. Use react-native in a monorepo (lerna) or just put all react-native files (except node_modules) in a sub directory to simulate it
  2. Run CLI tools (appcenter codepush release-react... or gradlew assembleRelease with hermes enabled)

Expected Behavior

Code push CLI commands should work.

Actual Behavior

Code push CLI fails because it's looking for node_modules in wrong location.

My folder structure: root_folder -node_modules -packages/mobile/node_modules

So CLI is looking for dependencies inside root_folder/packages/mobile/node_modules, but they are actually in root_folder/node_modules.

Deploying

For deploying with code-push CLI I've used this workaround:

cd packages\mobile
mv node_modules node_modules_tmp
mklink /D node_modules ..\..\node_modules
call appcenter codepush release-react -a PRoject/android -d Staging -t 0.X.X
rm node_modules
mv node_modules_tmp node_modules
cd ..\..
node_modules\.bin\lerna exec --scope=@*/mobile -- yarn code-push:android-list

Exception for deploying without workaround above:

Error: Cannot find module C:\Users\user\WebstormProjects\project\packages\mobile\node_modules\react-native\local-cli\cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
Error: Failed to release a CodePush update.

Building in Ubuntu (From Windows app store)

react-native solves this issue by providing config via build.gradle, so I was able to get react-native working with monorepo and hermes enabled, but I got stuck at code-push: https://github.com/react-native-community/cli/issues/877 Maybe code-push can use similar?

For build with hermes enabled I get this error:

STACK TRACE AND/OR SCREENSHOTS
Error: Cannot find module '/mnt/c/Users/user/WebstormProjects/project/packages/mobile/node_modules"/react-native-code-push/scripts/generateBundledResourcesHash.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

...notice that it's looking for node_modules folder in wrong location.

EDIT: I've also noticed that there is an extra double quote inside the path node_modules"/react-native-code-push and it may be failing because of that...but strangely this works on Windows (build succeeds with same files, including unchanged node_modules).

Reproducible Demo

Since issue is obvious I didn't decide to create a repo with it yet, but if needed I can do it. As stated above, the only issue is in how folders are placed, so one can easily reproduce by putting his react-native files in a project sub folder (/packages/mobile/ in my case), but keeps node_modules folder in root directory (next to my packages directory).

Environment

  • react-native-code-push version: ^6.2.0
  • react-native version: ^0.62.2
  • iOS/Android/Windows version: Running CLI on windwos and Ubuntu emulator from app store.
  • Does this reproduce on a debug build or release build? On all that have code-push enabled (release and releasestaging builds in my case, disabled on debug).
  • Does this reproduce on a simulator, or only on a physical device? It happens when building a project (with hermes enabled) or when deploying changes via CLI.

tad3j avatar Jun 02 '20 15:06 tad3j

Any updates here?

joeyfigaro avatar Jan 26 '21 17:01 joeyfigaro

You can currently work around it by creating a symlink, for example:

// File: <monorepo>/scripts/deploy-to-code-push.js

const appDir = join(__dirname, '../apps/app')

// AppCenter will try to use hermes-engine from the local node_modules
// instead of the hoisted one, so we create a symlink and it'll work
execSync(
  'ln -sfr ../../node_modules/hermes-engine ./node_modules/hermes-engine',
  { cwd: appDir, stdio: 'inherit' },
)

execSync(
  [
    'npx',
    'appcenter-cli',
    'codepush',
    'release-react',
    `--app ${CODE_PUSH_APP}`,
    '--deployment-name Default',
    '--disable-duplicate-release-error',
    '--target-binary-version "*"',
    `--token ${APP_CENTER_ACCESS_TOKEN}`,
  ].join(' '),
  { cwd: appDir, stdio: 'inherit' },
)

gustavopch avatar Jan 26 '21 18:01 gustavopch

any updates?

privatepej avatar Nov 22 '23 02:11 privatepej

Hi @tad3j, could you please confirm what this issue still persist on latest version (8.2.1)? If no, cloud you please confirm what this workaround working for you?

MikhailSuendukov avatar Jan 29 '24 16:01 MikhailSuendukov

Hello @tad3j, we haven't heard from you for a while, so I'm closing this issue. Please, feel free to reopen it in case of new information.

AnatolyPristensky avatar Feb 12 '24 14:02 AnatolyPristensky