skip to Main Content

I upgraded my RN project from 0.71.12 to 0.75.2 and I’m able to run both Android and iOS project in my local. For the app release I’m able to build and deliver Android project to Google Play Console by using App Center but for the iOS project I get errors like this from App Center iOS pipeline:

[command]/bin/bash --noprofile --norc /Users/runner/work/_temp/db95f9b0-01e7-4cb3- 
bd0d-4970e0cd7b11.sh
Found index.js for ReactNative index.
node:internal/modules/cjs/loader:1143
throw err;
^ 

Error: Cannot find module '/Users/runner/work/1/s/apps/mobile/node_modules/react- 
native/local-cli/cli.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
at Module._load (node:internal/modules/cjs/loader:981:27)
at Function.executeUserEntryPoint [as runMain] 
(node:internal/modules/run_main:128:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
} 

Node.js v18.20.4

enter image description here

Does anyone have an idea where the issue might come from?

My project is a mono repo containing a React project and a React Native one.

2

Answers


  1. I spend the entire day yesterday trying to figure out a solution and landed on a somewhat basic (and maybe hacky) solution but it worked.

    The problem was that since RN 0.75.0 the /local-cli/cli.js file is no longer available but AppCenter is expecting it. I simply re-added this cli.js file using https://www.npmjs.com/package/patch-package.

    This resulted in the following `packages/react-native+0.75.2.patch file:

    diff --git a/node_modules/react-native/local-cli/cli.js b/node_modules/react-native/local-cli/cli.js
    new file mode 100644
    index 0000000..1f38951
    --- /dev/null
    +++ b/node_modules/react-native/local-cli/cli.js
    @@ -0,0 +1,18 @@
    +/**
    + * Copyright (c) Meta Platforms, Inc. and affiliates.
    + *
    + * This source code is licensed under the MIT license found in the
    + * LICENSE file in the root directory of this source tree.
    + *
    + * @format
    + */
    +
    +'use strict';
    +
    +var cli = require('@react-native-community/cli');
    +
    +if (require.main === module) {
    +    cli.run();
    +}
    +
    +module.exports = cli;
    

    After this the build succeeded. Hope this helps.

    Login or Signup to reply.
  2. This problem is related to appcenter-cli which is being installed globally inside our Users/<username>/AppData/Roaming/nvm/<your-node-version>/node_modules/appcenter-cli/dist/commands/codepush/lib/react-native-utils.js. Here is a method present getCliPath where it is mentioned to add local-cli as a path. But recent react-native 0.75.0 or above this path is removed. So just removing this path should work.

    function getCliPath() {
        if (process.platform === "win32") {
            // return path.join(getReactNativePackagePath(), "local-cli", "cli.js"); 
            return path.join(getReactNativePackagePath(), "cli.js"); // Use this way
        }
        return path.join("node_modules", ".bin", "react-native");
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search