【问题标题】:Invalid `Podfile` file: 767: unexpected token at ''无效的 `Podfile` 文件:767:\'\' 处的意外令牌
【发布时间】:2022-10-14 15:11:52
【问题描述】:

我正在尝试使用 react native 运行我的 IOS 应用程序,但我需要更新我的 Pod。所以我在终端上运行:

cd iOS && pod install

但我在标题上收到此错误

internal/modules/cjs/loader.js:888
  throw err;
  ^

Error: Cannot find module '/Users/my-user/Documents/Test/my-app/ios/undefined'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:885:15)
    at Function.Module._load (internal/modules/cjs/loader.js:730:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

[!] Invalid `Podfile` file: 767: unexpected token at ''.
#  from /Users/my-user/Documents/Test/my-app/ios/Podfile:12
#  -------------------------------------------
#  
>    use_native_modules!
#  end
#  -------------------------------------------

我应该怎么办?

我的 Podfile 如下

# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'


target 'MyApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp

  use_native_modules!
end

我的 package.json 文件使用了这个依赖:

"dependencies": {
  "@react-native-community/async-storage": "^1.12.1",
  "@react-native-community/cli-platform-ios": "^3.0.0",
  "@react-native-community/netinfo": "8.3.0",
  "@sentry/react-native": "3.4.3",
  "@virgilsecurity/e3kit": "^0.7.0-beta.2",
  "@virgilsecurity/key-storage-rn": "^0.2.1",
  "appcenter-cli": "^2.1.2",
  "moment": "2.29.3",
  "react": "16.9.0",
  "react-native": "0.61.3",
  "react-native-calendars": "1.259.0",
  "react-native-code-push": "6.0.0",
  "react-native-extended-stylesheet": "^0.12.0",
  "react-native-fast-image": "^8.5.11",
  "react-native-fbsdk": "^3.0.0",
  "react-native-firebase": "^5.5.6",
  "react-native-fs": "^2.14.1",
  "react-native-gifted-chat": "^0.13.0",
  "react-native-image-picker": "^1.0.2",
  "react-native-keep-awake": "^4.0.0",
  "react-native-keychain": "^4.0.1",
  "react-native-masked-text": "^1.13.0",
  "react-native-push-notification": "^8.1.1",
  "react-native-twilio-video-webrtc": "^2.0.0",
  "react-native-vector-icons": "^5.0.0",
  "react-native-virgil-crypto": "^0.6.1",
  "react-native-webview": "^7.4.1",
  "react-redux": "^8.0.2",
  "react-router": "^5.1.2",
  "react-router-dom": "^5.1.2",
  "react-router-native": "^5.1.2",
  "realm": "6.0.3",
  "redux": "^4.2.0",
  "redux-thunk": "^2.4.1"
},

如果我使用 use_native_modules!在代码之外,它可以正常工作。但和他没有

【问题讨论】:

  • 它发生在 React Native 0.69.0 中。我也遵循了适当的迁移指南,但没有奏效。我也在等决议。
  • 嘿@IOSDev,就我而言,我使用的是“react-native”:“0.61.3”,

标签: react-native cocoapods


【解决方案1】:

最后!!!通常,要安装我的 pod,我只需要做 3 件事。

1- 取出包装@react-native-community/cli-platform-ios来自 package.json

2- 在终端上,访问主应用程序文件夹并更新 node_modules 上的更改

yarn

3- 访问 iOS 页面并安装 pod

cd ios && pod install

【讨论】:

    【解决方案2】:

    我通过禁用 VS Code 的调试器自动附加功能在我的机器上解决了这个问题。该功能导致 Node 发出额外的控制台输出,native_modules.rb 文件无法解析。

    此错误可能是由任意数量的本地配置问题引起的。所以我的解决方案可能不适合你。如果禁用 VS Code 自动附加不能为您解决问题,您可以通过以下方式进行更多调查:

    unexpected token at '' 是一个JavaScript错误。如果您转到产生错误的 Ruby 文件(通常是 ../node_modules/@react-native-community/cli-platform-ios/native_modules.rb),您可以看到它正在尝试使用 Node.js 从您的 node_modules 打开一些 JS 文件。在您的终端中,cd 到 native_modules.rb 文件的位置并尝试在您的终端上执行 Node 命令 - 您可能会获得更多关于系统上正在发生的事情的线索。祝你好运。

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 2018-05-12
      • 2019-05-22
      • 1970-01-01
      相关资源
      最近更新 更多