React-native: babel-plugin-module-resolver doesn't work with react-native 0.63.0+ for iOS production builds

Created on 13 Aug 2020  路  6Comments  路  Source: facebook/react-native

Description

In my react-native project I'm using babel-plugin-module-resolver plugin to achieve relative short path for the modules, files, directories. When I mograted from [email protected] to [email protected] I found that iOS Production build cannot be assembled. Xcode throws Error 65 during build with Fastlane on CI. Manually locally in Xcode it throws the same error for Production builds. Development builds work fine.
After debugging I found that relative paths cannot be resolved correctly in [email protected]. Reverted to 0.62 version -works fine...

React Native version:

System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 197.68 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.5.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.7 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 11.6/11E708 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.2 => 0.63.2 

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Use [email protected] with short imports in project, use [email protected]+
  2. Assemble release iOS build in xcode

Expected Results

Release iOS build assembled succesfully.

Already raised issues:

For the babel plugin we already have this issue: https://github.com/tleunen/babel-plugin-module-resolver/issues/403
But the reason in react-native codebase changes, because 0.62 version works fine.

Also we have a PR in react-native repo, that reverts some code for index.ios.js file detection, possibly related to this issue:
facebook/react-native#29477

Could you please guys pay attention here, because a lot of production projects use this babel plugin. Thanks

Logs from xcode:

warning: the transform cache was reset.
                 Welcome to React Native!
                Learn once, write anywhere

error src/features/search/container.js: Cannot find module '../shared/queries/search.query.gql'
Require stack:
- /Users/my-project/mobile-web-app/node_modules/babel-plugin-import-graphql/build/index.js
- /Users/my-project/mobile-web-app/node_modules/@react-native-community/cli/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/config/files/plugins.js
- /Users/my-project/mobile-web-app/node_modules/@react-native-community/cli/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/config/files/index.js
- /Users/my-project/mobile-web-app/node_modules/@react-native-community/cli/node_modules/metro-react-native-babel-transformer/node_modules/@babel/core/lib/index.js
- /Users/my-project/mobile-web-app/node_modules/@react-native-community/cli/node_modules/metro-react-native-babel-transformer/src/index.js
- /Users/my-project/mobile-web-app/node_modules/metro/src/JSTransformer/worker.js
- /Users/my-project/mobile-web-app/node_modules/metro/src/DeltaBundler/Worker.js
- /Users/my-project/mobile-web-app/node_modules/metro/node_modules/jest-worker/build/workers/processChild.js. Run CLI with --verbose flag for more details.

+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'
React Native, please report it here: https://github.com/facebook/react-native/issues
+ exit 2

File ../shared/queries/search.query.gql can't be resolved, it is defined as relative path with babel plugin:
import searchQuery from "core/shared/queries/search.query.gql"

iOS PR Submitted

Most helpful comment

All 6 comments

@oleksandr-dziuban version babel-plugin-module-resolver ?

@oleksandr-dziuban version babel-plugin-module-resolver ?

@riadhriadh
The latest v4.0.0

@riadhriadh Yes, I can confirm, this PR fixes the issue:
https://github.com/facebook/react-native/pull/29477

I have assembled release iOS build locally with this change and it works!
We need to ask maintainers to merge this PR... But there is no activity on it now...

I'm currently going through this, I'm trying to run "Product > Archive" to build for appstore but it always fails with A module not being found but it works well on android, I have also tried running debug on iphone simulator and it works well with no error...

Upgrade to v0.63.3. It's now fixed

Changelog of v0.63.3 :

  • Fix "main.jsbundle does not exist" issue (83777cb4fb)
Was this page helpful?
0 / 5 - 0 ratings