ios – React-Native:main.jsbundle不存在.这必须是“无法将对象转换为原始值”的错误

我的项目信息

React Native Environment Info:
System:
  OS: macOS High Sierra 10.13.6
  CPU: x64 Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz
  Memory: 241.64 MB / 8.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
    Node: 8.11.3 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.2.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
    iOS SDK:
        Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
    Android SDK:
        Build Tools: 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.2
    API Levels: 23, 24, 25, 26, 27
IDEs:
    Android Studio: 3.0 AI-171.4408382
    Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
    react: 16.4.1 => 16.4.1 
    react-native: 0.56.0 => 0.56.0 
npmGlobalPackages:
    create-react-native-app: 1.0.0
    react-native-camera: 0.9.0
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7
    react-native-maps: 0.15.2
    react-native-vector-icons: 4.0.0

作为Dev运行项目工作正常,但作为Release运行会产生以下错误.

warning: the transform cache was reset.
Loading dependency graph, done.

/Users/macintoshhd/Documents/TGS/mow/node_modules/rx/dist/rx.all.js: Cannot convert object to primitive value

+ [[ false != true ]]
+ [[ ! -f /Users/macintoshhd/Library/Developer/Xcode/DerivedData/mow-ekmdxdpkhrpqmmdbccixjzdqelmg/Build/Products/Release-iphoneos/mow.app/main.jsbundle ]]
+ echo 'error: File /Users/macintoshhd/Library/Developer/Xcode/DerivedData/mow-ekmdxdpkhrpqmmdbccixjzdqelmg/Build/Products/Release-iphoneos/mow.app/main.jsbundle does not exist. This must be a bug with'

我试图用–dev = false手动捆绑项目

react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'

我得到了这个错误输出

Scanning folders for symlinks in /Users/macintoshhd/Documents/myproject/node_modules (41ms)
Scanning folders for symlinks in /Users/macintoshhd/Documents/myproject/node_modules (29ms)
Loading dependency graph, done.

/Users/macintoshhd/Documents/myproject/node_modules/rx/dist/rx.all.js: Cannot convert object to primitive value

将–dev = false更改为–dev = true,这些输出的buid成功

react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=true --platform='ios' --assets-dest='./ios'

Scanning folders for symlinks in /Users/macintoshhd/Documents/TGS/mow/node_modules (15ms)
Scanning folders for symlinks in /Users/macintoshhd/Documents/TGS/mow/node_modules (17ms)
Loading dependency graph, done.
bundle: Writing bundle output to: ./ios/mow/main.jsbundle
bundle: Done writing bundle output
bundle: Copying 31 asset files
bundle: Done copying assets

我试过了
– 清洁和重建
– 删除node_modules并重新安装
– 清理Derived文件夹,重启Xcode,
但他们都没有解决这个问题.

这似乎是主要问题.

/Users/macintoshhd/Documents/TGS/mow/node_modules/rx/dist/rx.all.js: Cannot convert object to primitive value

你有什么建议吗,请帮忙.
谢谢!

最佳答案 我花了几天时间来计算node_modules / rx / dist / rx.all.js的原因:无法通过注释所有代码并逐个取消注释将对象转换为原始值错误.

当我在自动完成弹出窗口后巧合按Enter键时,VS Code会自动导入未知库.它是

import { AsyncSubject } from 'rx';

删除import语句后,我在Release模式下成功构建项目.

当以Dev模式运行时,这种错误不会抛出异常:(,除了为Release构建时.

点赞