Search code examples
iosreact-nativeopenssl

TypeError: Cannot read properties of undefined (reading 'transformFile'), Command PhaseScriptExecution failed with a nonzero exit code


React native iOS archive build fails with an exception Command PhaseScriptExecution failed with a nonzero exit code.

In Android & ios app is working fine, while trying to achieve it will give error:

Configuration
OS: macOS 14.0
Node: 21.5.0 - /usr/local/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 10.2.4 - /usr/local/bin/npm
CocoaPods: 1.14.3 - /usr/local/bin/pod
react: 17.0.2 => 17.0.2 
react-native: 0.66.1 => 0.66.1 



Failed to construct transformer:  Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:68:19)
    at Object.createHash (node:crypto:138:10)
    at stableHash (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-cache/src/stableHash.js:19:8)
    at Object.getCacheKey (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-transform-worker/src/index.js:593:7)
    at getTransformCacheKey (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/getTransformCacheKey.js:24:19)
    at new Transformer (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/Transformer.js:48:9)
    at /Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/Bundler.js:22:29 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
error Cannot read properties of undefined (reading 'transformFile').
TypeError: Cannot read properties of undefined (reading 'transformFile')
    at Bundler.transformFile (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/Bundler.js:48:30)
    at async Object.transform (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/lib/transformHelpers.js:101:12)
    at async processModule (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:137:18)
    at async traverseDependenciesForSingleFile (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:131:3)
    at async Promise.all (index 0)
    at async initialTraverseDependencies (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/traverseDependencies.js:114:3)
    at async DeltaCalculator._getChangedDependencies (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:164:25)
    at async DeltaCalculator.getDelta (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler/DeltaCalculator.js:94:16)
    at async DeltaBundler.buildGraph (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/DeltaBundler.js:50:5)
    at async IncrementalBundler.buildGraphForEntries (/Users/vishal/Work/RN_Project/HOST/host-react-native/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/IncrementalBundler.js:80:19)
info Run CLI with --verbose flag for more details.
Command PhaseScriptExecution failed with a nonzero exit code

metro.config.js

const { getDefaultConfig } = require('metro-config');
module.exports = async () => {
  const {
    resolver: { sourceExts, assetExts },
  } = await getDefaultConfig();
  return {
    transformer: {
      babelTransformerPath: require.resolve('react-native-svg-transformer'),
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: true,
        },
      }),
    },
    resolver: {
      assetExts: assetExts.filter((ext) => ext !== 'svg'),
      sourceExts: [...sourceExts, 'svg'],
    },
  };
};

Tried solution

01. export NODE_OPTIONS=--openssl-legacy-provider
02. nvm unalias default
03. Many time remove node-modules and build again
04. Many times update cocoapod & pods 

Solution

  • After research below solution work for me,

    Add below line in "~/.zshrc" file

    export NODE_OPTIONS=--openssl-legacy-provider
    

    Add "NODE_OPTIONS=--openssl-legacy-provider" in XCode, "Build Phases >> Bundel React Native code and images" section enter image description here

    Don't forgot to quit terminal and start again.

    Now the most important change is, replace '-' with '+' sign in "node_modules >> react-native >> scripts>> find-node.sh" file (Check below image) enter image description here