This package itself specifies a `main` module field that could not be resolved

Viewed 2121

Trying to run a react-native project that has x-resources package as dependency, installed the dependencies using yarn, but when i try to run the project i get this error at run time

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)

There is no /dist folder in this package and i can't understand why it's looking for index.js inside it, i don't know if it's a metro related issue or it's specific to this package, i've tried closing the running js server multiple times but no luck.

  • react: 16.9.0

  • react-native: 0.61.4

  • x-resources: 1.1.2

  • axios: 0.19.0

1 Answers

I solved this by cleaning my dependencies.

Delete:

  • node_modules/
  • yarn.lock (or package-lock.json)
  • ios/Pods (and/or packages/mobile/ios/Pods)
  • ios/Podfile.lock (and/or packages/mobile/ios/Podfile.lock)

Then run:

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

In my case, it seems I had some misconfiguration after moving from the classic npm layout to "monorepo".

Related