3

尝试运行将x-resources包作为依赖项的 react-native 项目,使用 yarn 安装了依赖项,但是当我尝试运行该项目时,我在运行时收到此错误

bundling failed: Error: While trying to resolve module `x-resources` from file `/***/index.js`, the package `/***/node_modules/x-resources/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/***/node_modules/x-resources/dist/index.js`. Indeed, none of these files exist:

 *  /***/node_modules/x-resources/dist/index.js(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
 * /***/node_modules/x-resources/dist/index.js/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)

    at ResolutionRequest.resolveDependency (/***/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:65:15)
    at DependencyGraph.resolveDependency (/***/node_modules/metro/src/node-haste/DependencyGraph.js:282:16)
    at Object.resolve (/***/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at /***/node_modules/metro/src/DeltaBundler/traverseDependencies.js:426:31
    at Array.map (<anonymous>)
    at resolveDependencies (/***/node_modules/metro/src/DeltaBundler/traverseDependencies.js:423:18)
    at /***/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/***/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)
    at _next (/***/node_modules/metro/src/DeltaBundler/traverseDependencies.js:107:9)

这个包中没有/dist文件夹,我不明白为什么它在里面寻找 index.js,我不知道这是与地铁相关的问题还是特定于这个包,我已经尝试关闭运行js服务器多次但没有运气。

  • 反应:16.9.0

  • 反应原生:0.61.4

  • x资源:1.1.2

  • axios:0.19.0

4

1 回答 1

0

我通过清理我的依赖项解决了这个问题。

删除:

  • node_modules/
  • yarn.lock(或package-lock.json
  • ios/Pods(和/或packages/mobile/ios/Pods
  • ios/Podfile.lock(和/或packages/mobile/ios/Podfile.lock

然后运行:

  • yarn # or npm install
  • cd ios # or packages/mobil/ios
  • pod update
  • pod install
  • say done

就我而言,从经典的 npm 布局转移到“ monorepo ”后,我似乎配置了一些错误。

于 2022-01-28T11:44:06.813 回答