类型错误:无法读取未定义的属性(读取“transformFile”),命令 PhaseScriptExecution 失败,退出代码非零

问题描述 投票:0回答:1

React 本机 iOS 存档构建失败并出现异常 命令 PhaseScriptExecution 失败,退出代码非零。

在 Android 和

ios
应用程序工作正常,但尝试实现它时会出现错误:

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'],
    },
  };
};

已尝试解决方案

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 
ios react-native openssl
1个回答
0
投票

经过研究,以下解决方案对我有用,

在“~/.zshrc”文件中添加以下行

export NODE_OPTIONS=--openssl-legacy-provider

在 XCode 中添加“NODE_OPTIONS=--openssl-legacy-provider”,“构建阶段 >> Bundel React Native 代码和图像”部分

不要忘记退出终端并重新启动。

现在最重要的变化是,将“node_modules >> react-native >> script>> find-node.sh”文件中的“-”替换为“+”(查看下图)

© www.soinside.com 2019 - 2024. All rights reserved.