You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native项目Expo构建失败:本地代码正常但打包报错

问题描述

我正在开发一个React Native应用,想用Expo构建包提交苹果审核,但每次执行Expo构建都会在同一行代码处失败。本地运行完全正常,不知道问题出在哪。

相关代码

import React, { useState, useEffect } from 'react'
import { View, Text, StyleSheet, TouchableOpacity, TextInput } from 'react-native'
import { Feather } from 'react-native-vector-icons'
import axios from 'axios'

import PropertySampleComponent from '../components/GeneralComponents/PropertySampleComponent'
import ContactAgentComponent from '../components/PropertyScreenComponents.js/ContactAgentComponent'

import { extendedPropertOptions, singlePropertyOptions } from '../../zillow.js'

const ContactAgentScreen = ({route}) => {

  const [addressLookup, setAddressLookup] = useState('')
  const [currentHome, setCurrentHome] = useState({})

  useEffect(() => {
    if(route.params?.zpid){
      getPropertyDetails(route.params.zpid)
    }
  }, [])

  const newSearch = () => {
    extendedPropertOptions.params.location = addressLookup
    axios.request(extendedPropertOptions)
      .then((response) => {
        Object.keys(response.data).length == 1 ? getPropertyDetails(response.data.zpid) : console.log('no detail found')
      })
      .catch((error) => {
        console.log(error)
      })
  }

  const getPropertyDetails = (zpid) => {
    singlePropertyOptions.params.zpid = zpid
    axios.request(singlePropertyOptions)
      .then((response) => {
        setCurrentHome(response.data)
      })
      .catch((error) => {
        console.log(error)
      })
  }

  return (
    <View style={styles.container}>
      <View style={styles.header}>
        <Text style={styles.headerText}>Connect With An Agent</Text>
      </View>
      <View style={styles.row}>
        <Feather style={styles.chevronDown} size={20} name='search'/>
        <TextInput 
          value={addressLookup}
          style={styles.input}
          onChangeText={setAddressLookup}
          placeholder={'Enter an address'}
        />
        <TouchableOpacity style={styles.searcingContainer} onPress={() => {newSearch()}}>
          <Text style={styles.searchSubmit}>Search</Text>
        </TouchableOpacity>
      </View>
      {
        Object.keys(currentHome).length == 0 ? null : <View style={styles.property}><PropertySampleComponent item={currentHome}/></View>
      }
      <ContactAgentComponent currentHome={currentHome}/>
    </View>
  )
}

...

Expo构建错误日志

› Executing Reipp » Bundle React Native code and images
    the transform cache was reset.
▸ ** ARCHIVE FAILED **
▸ The following build commands failed:
▸   PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/Library/Developer/Xcode/DerivedData/Reipp-gorbnnjknomygnfxwixidlmwggov/Build/Intermediates.noindex/ArchiveIntermediates/Reipp/IntermediateBuildFilesPath/Reipp.build/Release-iphoneos/Reipp.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'Reipp' from project 'Reipp')
▸ (1 failure)
2022-09-25 19:46:53.593 xcodebuild[4248:12379] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-09-25 19:46:53.593 xcodebuild[4248:12379] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-09-25 19:46:53.646 xcodebuild[4248:12379] XType: failed to connect - Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.fonts was invalidated: failed at lookup with error 3 - No such process." UserInfo={NSDebugDescription=The connection to service named com.apple.fonts was invalidated: failed at lookup with error 3 - No such process.}
2022-09-25 19:46:53.646 xcodebuild[4248:12379] Font server protocol version mismatch (expected:5 got:0), falling back to local fonts
2022-09-25 19:46:53.646 xcodebuild[4248:12379] XType: unable to make a connection to the font daemon!
2022-09-25 19:46:53.646 xcodebuild[4248:12379] XType: XTFontStaticRegistry is enabled as fontd is not available.
** ARCHIVE FAILED **
The following build commands failed:
    PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/Library/Developer/Xcode/DerivedData/Reipp-gorbnnjknomygnfxwixidlmwggov/Build/Intermediates.noindex/ArchiveIntermediates/Reipp/IntermediateBuildFilesPath/Reipp.build/Release-iphoneos/Reipp.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'Reipp' from project 'Reipp')
(1 failure)
Exit status: 65
+-------------+-------------------------+
|           Build environment           |
+-------------+-------------------------+
| xcode_path  | /Applications/Xcode.app |
| gym_version | 2.206.1                 |
| sdk         | iPhoneOS15.5.sdk        |
+-------------+-------------------------+
Looks like fastlane ran into a build/archive error with your project
It's hard to tell what's causing the error, so we wrote some guides on how
to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
Before submitting an issue on GitHub, please follow the guide above and make
sure your project is set up correctly.
fastlane uses `xcodebuild` commands to generate your binary, you can see the
the full commands printed out in yellow in the above log.
Make sure to inspect the output above, as usually you'll find more error information there
[stderr] [!] Error building the application - see the log above
error Unable to resolve module ../../zillow.js from /Users/expo/workingdir/build/Reipp/src/screens/ContactAgentScreen.js: 

None of these files exist:
  * zillow.js(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  * zillow.js/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
   7 | import ContactAgentComponent from '../components/PropertyScreenComponents.js/ContactAgentComponent'
   8 |
>  9 | import { extendedPropertOptions, singlePropertyOptions } from '../../zillow.js'
     |                                                                ^
  10 |
  11 | const ContactAgentScreen = ({route}) => {
  12 |.
Error: Unable to resolve module ../../zillow.js from /Users/expo/workingdir/build/Reipp/src/screens/ContactAgentScreen.js: 

None of these files exist:
  * zillow.js(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  * zillow.js/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
   7 | import ContactAgentComponent from '../components/PropertyScreenComponents.js/ContactAgentComponent'
   8 |
>  9 | import { extendedPropertOptions, singlePropertyOptions } from '../../zillow.js'
     |                                                                ^
  10 |
  11 | const ContactAgentScreen = ({route}) => {
  12 |
    at ModuleResolver.resolveDependency (/Users/expo/workingdir/build/Reipp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:136:15)
    at DependencyGraph.resolveDependency (/Users/expo/workingdir/build/Reipp/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
    at Object.resolve (/Users/expo/workingdir/build/Reipp/node_modules/metro/src/lib/transformHelpers.js:129:24)
    at resolve (/Users/expo/workingdir/build/Reipp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
    at /Users/expo/workingdir/build/Reipp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
    at Array.reduce (<anonymous>)
    at resolveDependencies (/Users/expo/workingdir/build/Reipp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
    at processModule (/Users/expo/workingdir/build/Reipp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:140:31)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
info 
Error: Fastlane build failed with unknown error. See logs for the "Run fastlane" and "Xcode Logs" phases for more information.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when looking for an error message.

解决方案

从错误日志可明确核心问题:Expo构建时找不到../../zillow.js文件,本地正常但构建失败,大概率是以下原因导致:

1. 文件路径或名称不符

  • 核对路径:当前文件在src/screens/ContactAgentScreen.js,../../zillow.js意味着文件应在项目根目录与src同级的位置(如Reipp/zillow.js),确认文件实际存在且路径正确。
  • 检查大小写:Mac本地文件系统不区分大小写,但Expo构建环境严格区分,确保文件名大小写与import语句完全一致(比如不要写成Zillow.js)。

2. 文件被.gitignore排除

若zillow.js包含敏感信息(如API密钥),可能被加入.gitignore,导致构建服务器拉取代码时缺失该文件。解决办法:

  • 将敏感信息迁移至环境变量,用Expo内置的环境变量管理方案或dotenv工具处理。
  • 若必须保留该文件,从.gitignore中移除对应规则并提交至代码仓库。

3. Metro缓存或配置问题

本地Metro可能缓存了路径,或配置允许省略扩展名,但构建环境的Metro配置更严格。可尝试:

  • 清除Metro缓存:执行npx expo start --clear后重新发起构建。
  • 确保import语句中的文件扩展名正确,比如文件是zillow.jsx就必须写成../../zillow.jsx。

4. 构建环境与本地文件结构差异

本地开发时的额外目录可能未同步到构建服务器,导致路径匹配失败。可:

  • 打印项目根目录的文件结构,对比本地与构建环境的差异。
  • 确认zillow.js处于正确目录,且被正确打包进构建产物。

内容的提问来源于stack exchange,提问作者ojandali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 02:20:36