Metro cannot resolve paths

Viewed 656

When I run fastlane to deploy a beta version of my app. It crashes with an error relating to PhaseScriptExecution Bundle 65. I found that I can recreate the error with CONFIGURATION=1 ./node_modules/react-native/scripts/react-native-xcode.sh

That command crashes at https://github.com/facebook/metro/blob/v0.71.0/packages/metro/src/node-haste/DependencyGraph.js#L207 with

SHA-1 for file /project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph/assets/empty-module.js (/project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph/assets/empty-module.js) is not computed.
         Potential causes:
           1) You have symlinks in your project - watchman does not follow symlinks.
           2) Check `blockList` in your metro.config.js and make sure it isn't excluding the file path.

I'm not sure what is happening, but going back to a previous commit or doing rm -rf node_modules; npm i does not solve it.

I found https://github.com/facebook/metro/issues/330#issue-389608574 and tried the proposed workaround (vi node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph.js), but then I run CONFIGURATION=1 ./node_modules/react-native/scripts/react-native-xcode.sh and I get:

error Unable to resolve module /project/node_modules/metro-runtime/src/modules/asyncRequire.js from /project/.: 

None of these files exist:
  * ../project/node_modules/metro-runtime/src/modules/asyncRequire.js(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  * ../project/node_modules/metro-runtime/src/modules/asyncRequire.js/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx).
Error: Unable to resolve module /project/node_modules/metro-runtime/src/modules/asyncRequire.js from /project/.: 

None of these files exist:
  * ../project/node_modules/metro-runtime/src/modules/asyncRequire.js(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
  * ../project/node_modules/metro-runtime/src/modules/asyncRequire.js/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (/project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:107:15)
    at DependencyGraph.resolveDependency (/project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/node-haste/DependencyGraph.js:295:43)
    at /project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/lib/transformHelpers.js:129:24
    at Server._resolveRelativePath (/project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/Server.js:1072:12)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Server.build (/project/node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/src/Server.js:139:31)
    at async buildBundleWithConfig (/project/node_modules/@react-native-community/cli-plugin-metro/build/commands/bundle/buildBundle.js:110:20)
    at async Command.handleAction (/project/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.

I check and the file exists....

project % cat node_modules/metro-runtime/src/modules/asyncRequire.js
/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @format
 *
 */
"use strict"; // $FlowExpectedError Flow does not know about Metro's require extensions.

const dynamicRequire = require;

module.exports = function(moduleID) {
  return Promise.resolve().then(() => dynamicRequire.importAll(moduleID));
};
project % 

I'm not sure what I should try next?

PS:

Also, I check for symlinks and I find a bunch in node_modules, and none for node-haste. I don't understand how metro is complaining about node-haste and not all the other ones.

project % find . -type l -ls | grep -v -E ios.Pods | grep metro          
37860573        0 lrwxr-xr-x    1 kevin            staff                  89 May 28 21:23 ./node_modules/.bin/metro-inspector-proxy -> ../@react-native-community/cli-plugin-metro/node_modules/metro-inspector-proxy/src/cli.js
37860574        0 lrwxr-xr-x    1 kevin            staff                  87 May 28 21:23 ./node_modules/.bin/metro-symbolicate -> ../@react-native-community/cli-plugin-metro/node_modules/metro-symbolicate/src/index.js
37860607        0 lrwxr-xr-x    1 kevin            staff                  19 May 28 21:23 ./node_modules/.bin/metro -> ../metro/src/cli.js
37860477        0 lrwxr-xr-x    1 kevin            staff                  42 May 28 21:23 ./node_modules/metro-transform-worker/node_modules/.bin/parser -> ../../../@babel/parser/bin/babel-parser.js
37860478        0 lrwxr-xr-x    1 kevin            staff                  25 May 28 21:23 ./node_modules/metro-transform-worker/node_modules/.bin/metro -> ../../../metro/src/cli.js
37860481        0 lrwxr-xr-x    1 kevin            staff                  28 May 28 21:23 ./node_modules/metro-transform-worker/node_modules/metro-cache/node_modules/.bin/rimraf -> ../../../../../rimraf/bin.js
37860484        0 lrwxr-xr-x    1 kevin            staff                  39 May 28 21:23 ./node_modules/metro-transform-worker/node_modules/metro-source-map/node_modules/.bin/metro-symbolicate -> ../../../metro-symbolicate/src/index.js
37860440        0 lrwxr-xr-x    1 kevin            staff                  22 May 28 21:23 ./node_modules/metro-cache/node_modules/.bin/rimraf -> ../../../rimraf/bin.js
37860439        0 lrwxr-xr-x    1 kevin            staff                  26 May 28 21:23 ./node_modules/metro-cache/node_modules/.bin/mkdirp -> ../../../mkdirp/bin/cmd.js
37860214        0 lrwxr-xr-x    1 kevin            staff                  19 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/.bin/metro -> ../metro/src/cli.js
37860240        0 lrwxr-xr-x    1 kevin            staff                  51 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-transform-worker/node_modules/.bin/parser -> ../../../../../../@babel/parser/bin/babel-parser.js
37860241        0 lrwxr-xr-x    1 kevin            staff                  25 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-transform-worker/node_modules/.bin/metro -> ../../../metro/src/cli.js
37860228        0 lrwxr-xr-x    1 kevin            staff                  31 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-cache/node_modules/.bin/rimraf -> ../../../../../../rimraf/bin.js
37860218        0 lrwxr-xr-x    1 kevin            staff                  41 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/@react-native-community/cli-tools/node_modules/.bin/semver -> ../../../../../../../semver/bin/semver.js
37860217        0 lrwxr-xr-x    1 kevin            staff                  32 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/@react-native-community/cli-tools/node_modules/.bin/mime -> ../../../../../../../mime/cli.js
37860225        0 lrwxr-xr-x    1 kevin            staff                  31 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/node_modules/.bin/rimraf -> ../../../../../../rimraf/bin.js
37860223        0 lrwxr-xr-x    1 kevin            staff                  41 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/node_modules/.bin/metro-inspector-proxy -> ../../../metro-inspector-proxy/src/cli.js
37860224        0 lrwxr-xr-x    1 kevin            staff                  39 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/node_modules/.bin/metro-symbolicate -> ../../../metro-symbolicate/src/index.js
37860221        0 lrwxr-xr-x    1 kevin            staff                  51 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/node_modules/.bin/parser -> ../../../../../../@babel/parser/bin/babel-parser.js
37860222        0 lrwxr-xr-x    1 kevin            staff                  46 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro/node_modules/.bin/image-size -> ../../../../../../image-size/bin/image-size.js
37860231        0 lrwxr-xr-x    1 kevin            staff                  25 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-config/node_modules/.bin/metro -> ../../../metro/src/cli.js
37860237        0 lrwxr-xr-x    1 kevin            staff                  39 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-source-map/node_modules/.bin/metro-symbolicate -> ../../../metro-symbolicate/src/index.js
37860234        0 lrwxr-xr-x    1 kevin            staff                  40 May 28 21:23 ./node_modules/@react-native-community/cli-plugin-metro/node_modules/metro-minify-uglify/node_modules/.bin/uglifyjs -> ../../../../../../uglify-es/bin/uglifyjs
37860266        0 lrwxr-xr-x    1 kevin            staff                  51 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro-transform-worker/node_modules/.bin/parser -> ../../../../../../@babel/parser/bin/babel-parser.js
37860267        0 lrwxr-xr-x    1 kevin            staff                  25 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro-transform-worker/node_modules/.bin/metro -> ../../../metro/src/cli.js
37860247        0 lrwxr-xr-x    1 kevin            staff                  28 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/@react-native-community/cli-plugin-metro/node_modules/.bin/metro -> ../../../../metro/src/cli.js
37860260        0 lrwxr-xr-x    1 kevin            staff                  31 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro/node_modules/.bin/rimraf -> ../../../../../../rimraf/bin.js
37860257        0 lrwxr-xr-x    1 kevin            staff                  41 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro/node_modules/.bin/metro-inspector-proxy -> ../../../metro-inspector-proxy/src/cli.js
37860258        0 lrwxr-xr-x    1 kevin            staff                  48 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro/node_modules/.bin/metro-symbolicate -> ../../../../../../metro-symbolicate/src/index.js
37860255        0 lrwxr-xr-x    1 kevin            staff                  51 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro/node_modules/.bin/parser -> ../../../../../../@babel/parser/bin/babel-parser.js
37860256        0 lrwxr-xr-x    1 kevin            staff                  46 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro/node_modules/.bin/image-size -> ../../../../../../image-size/bin/image-size.js
37860259        0 lrwxr-xr-x    1 kevin            staff                  35 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro/node_modules/.bin/mkdirp -> ../../../../../../mkdirp/bin/cmd.js
37860263        0 lrwxr-xr-x    1 kevin            staff                  40 May 28 21:23 ./node_modules/@react-native-community/cli/node_modules/metro-minify-uglify/node_modules/.bin/uglifyjs -> ../../../../../../uglify-es/bin/uglifyjs
37860436        0 lrwxr-xr-x    1 kevin            staff                  22 May 28 21:23 ./node_modules/metro/node_modules/.bin/rimraf -> ../../../rimraf/bin.js
37860434        0 lrwxr-xr-x    1 kevin            staff                  41 May 28 21:23 ./node_modules/metro/node_modules/.bin/metro-inspector-proxy -> ../../../metro-inspector-proxy/src/cli.js
37860435        0 lrwxr-xr-x    1 kevin            staff                  33 May 28 21:23 ./node_modules/metro/node_modules/.bin/metro-symbolicate -> ../metro-symbolicate/src/index.js
37860432        0 lrwxr-xr-x    1 kevin            staff                  42 May 28 21:23 ./node_modules/metro/node_modules/.bin/parser -> ../../../@babel/parser/bin/babel-parser.js
37860433        0 lrwxr-xr-x    1 kevin            staff                  37 May 28 21:23 ./node_modules/metro/node_modules/.bin/image-size -> ../../../image-size/bin/image-size.js
37860487        0 lrwxr-xr-x    1 kevin            staff                  28 May 28 21:23 ./node_modules/metro/node_modules/metro-cache/node_modules/.bin/rimraf -> ../../../../../rimraf/bin.js
37860490        0 lrwxr-xr-x    1 kevin            staff                  22 May 28 21:23 ./node_modules/metro/node_modules/metro-config/node_modules/.bin/metro -> ../../../../src/cli.js
37860493        0 lrwxr-xr-x    1 kevin            staff                  39 May 28 21:23 ./node_modules/metro/node_modules/metro-source-map/node_modules/.bin/metro-symbolicate -> ../../../metro-symbolicate/src/index.js
37860466        0 lrwxr-xr-x    1 kevin            staff                  30 May 28 21:23 ./node_modules/metro-core/node_modules/jest-haste-map/node_modules/.bin/sane -> ../../../../../sane/src/cli.js
37860469        0 lrwxr-xr-x    1 kevin            staff                  27 May 28 21:23 ./node_modules/metro-core/node_modules/jest-util/node_modules/.bin/is-ci -> ../../../../../is-ci/bin.js
37860442        0 lrwxr-xr-x    1 kevin            staff                  19 May 28 21:23 ./node_modules/metro-config/node_modules/.bin/metro -> ../metro/src/cli.js
37860462        0 lrwxr-xr-x    1 kevin            staff                  48 May 28 21:23 ./node_modules/metro-config/node_modules/metro-transform-worker/node_modules/.bin/parser -> ../../../../../@babel/parser/bin/babel-parser.js
37860463        0 lrwxr-xr-x    1 kevin            staff                  25 May 28 21:23 ./node_modules/metro-config/node_modules/metro-transform-worker/node_modules/.bin/metro -> ../../../metro/src/cli.js
37860456        0 lrwxr-xr-x    1 kevin            staff                  28 May 28 21:23 ./node_modules/metro-config/node_modules/metro/node_modules/.bin/rimraf -> ../../../../../rimraf/bin.js
37860453        0 lrwxr-xr-x    1 kevin            staff                  41 May 28 21:23 ./node_modules/metro-config/node_modules/metro/node_modules/.bin/metro-inspector-proxy -> ../../../metro-inspector-proxy/src/cli.js
37860454        0 lrwxr-xr-x    1 kevin            staff                  45 May 28 21:23 ./node_modules/metro-config/node_modules/metro/node_modules/.bin/metro-symbolicate -> ../../../../../metro-symbolicate/src/index.js
37860451        0 lrwxr-xr-x    1 kevin            staff                  48 May 28 21:23 ./node_modules/metro-config/node_modules/metro/node_modules/.bin/parser -> ../../../../../@babel/parser/bin/babel-parser.js
37860452        0 lrwxr-xr-x    1 kevin            staff                  43 May 28 21:23 ./node_modules/metro-config/node_modules/metro/node_modules/.bin/image-size -> ../../../../../image-size/bin/image-size.js
37860455        0 lrwxr-xr-x    1 kevin            staff                  32 May 28 21:23 ./node_modules/metro-config/node_modules/metro/node_modules/.bin/mkdirp -> ../../../../../mkdirp/bin/cmd.js
37860445        0 lrwxr-xr-x    1 kevin            staff                  30 May 28 21:23 ./node_modules/metro-config/node_modules/jest-haste-map/node_modules/.bin/sane -> ../../../../../sane/src/cli.js
37860448        0 lrwxr-xr-x    1 kevin            staff                  27 May 28 21:23 ./node_modules/metro-config/node_modules/jest-util/node_modules/.bin/is-ci -> ../../../../../is-ci/bin.js
37860459        0 lrwxr-xr-x    1 kevin            staff                  37 May 28 21:23 ./node_modules/metro-config/node_modules/metro-minify-uglify/node_modules/.bin/uglifyjs -> ../../../../../uglify-es/bin/uglifyjs
37860475        0 lrwxr-xr-x    1 kevin            staff                  39 May 28 21:23 ./node_modules/metro-source-map/node_modules/.bin/metro-symbolicate -> ../../../metro-symbolicate/src/index.js
37860472        0 lrwxr-xr-x    1 kevin            staff                  31 May 28 21:23 ./node_modules/metro-minify-uglify/node_modules/.bin/uglifyjs -> ../../../uglify-es/bin/uglifyjs
project % 
1 Answers

Notice in the error message

error Unable to resolve module /project/node_modules/metro-runtime/src/modules/asyncRequire.js from /project/.: 

None of these files exist:
  * ../project/node_modules/metro-runtime/src/modules/asyncRequire.js(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)

At first it lists /project/... , then it lists ../project/.... Notice the ../ at the beginning.

It actually happens that the true directory of my project is /Project . With a capital P. However, the path here is ../project/... . I think that there is some issue there.

Anyhow, I just did mv Project project and the issue was fixed!

I think this might come in handy for anyone who does create react app Project.

Related