microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

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

Closed tad3j closed 8 months ago

tad3j commented 4 years ago

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

joeyfigaro commented 3 years ago

Any updates here?

gustavopch commented 3 years ago

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' },
)
privatepej commented 11 months ago

any updates?

MikhailSuendukov commented 9 months ago

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?

AnatolyPristensky commented 8 months ago

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.