Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Expo 42] Bare app build failing #13475

Closed
ivopr opened this issue Jul 2, 2021 · 30 comments · Fixed by #13494
Closed

[Expo 42] Bare app build failing #13475

ivopr opened this issue Jul 2, 2021 · 30 comments · Fixed by #13494

Comments

@ivopr
Copy link

ivopr commented Jul 2, 2021

Edit Due to a mix of different underlying causes, we have locked this issue. Please read through this comment to find out how you can resolve this issue.


Summary

Android app fails to build on Task :unimodules-react-native-adapter:compileDebugJavaWithJavac

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

No response

Environment

Expo CLI 4.7.2 environment info:
System:
OS: Windows 10 10.0.19043
Binaries:
Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
SDKs:
Android SDK:
API Levels: 26, 29, 30
Build Tools: 29.0.2, 30.0.3
System Images: android-28 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-S | Google Play Intel x86 Atom_64
IDEs:
Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085
npmPackages:
expo: ~42.0.0 => 42.0.0
react: 16.13.1 => 16.13.1
react-dom: 16.13.1 => 16.13.1
react-native: ~0.63.4 => 0.63.4
react-native-web: ~0.13.12 => 0.13.18
Expo Workflow: bare

Reproducible demo or steps to reproduce from a blank project

Initialize a new Expo Bare App
Setup typescript (only creating the tsconfig.json and installing the deps when prompted by expo start)
Add eslint (config universe/native and the plugin simple-import-sort)
Try to yarn android and it shoud fail on the task mentioned above

@ivopr ivopr added the needs validation Issue needs to be validated label Jul 2, 2021
@tomhicks
Copy link

tomhicks commented Jul 2, 2021

I'm also having an issue. I think I might be onto a fix though...

Can you run node --version from the command line and tell me the result?

@ivopr
Copy link
Author

ivopr commented Jul 2, 2021

@tomhicks it is stated above too, but its the LTS 14.17.1

@tomhicks
Copy link

tomhicks commented Jul 2, 2021

oh yep I missed that...🙉

Are there any more details on the build failure? I was having an issue specifically with symbol not found ExpoModulesPackageList and it turns out that expo-modules-autolinking requires Node 14. I was on Node 12 and it's fixed it by updating to 14.

@ivopr
Copy link
Author

ivopr commented Jul 2, 2021

Sorry for the delay, I'm getting the exact same error as you, could the reason be that I've installed node via choco?

require(expo-modules-autolinking)(process.argv.slice(1))
        ^

ReferenceError: expo is not defined
    at [eval]:1:9
    at Script.runInThisContext (vm.js:134:12)
    at Object.runInThisContext (vm.js:311:38)
    at internal/process/execution.js:77:19
    at [eval]-wrapper:6:22
    at evalScript (internal/process/execution.js:76:60)
    at internal/main/eval_string.js:23:3
C:\Users\ivopr\test\node_modules\@unimodules\react-native-adapter\android\src\main\java\org\unimodules\adapters\react\ModuleRegistryAdapter.java:26: error: cannot find symbol
    mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                  ^
  symbol:   class ExpoModulesPackageList
  location: class ModuleRegistryAdapter

I'll try changing node

@tomhicks
Copy link

tomhicks commented Jul 2, 2021

Can you run npm ls expo-modules-autolinking

@ivopr
Copy link
Author

ivopr commented Jul 2, 2021

npm ls expo-modules-autolinking

got this

`-- expo@42.0.0
  `-- @unimodules/react-native-adapter@6.3.1
    `-- expo-modules-autolinking@0.0.2

@tomhicks
Copy link

tomhicks commented Jul 2, 2021

I can kind of see your issue:

require(expo-modules-autolinking)(process.argv.slice(1))
        ^ This should be a string "expo-modules..."

That's somehow preventing the autolinking from working.

It's different from my issue, which was that the autolinking code uses nullish coalescing ?? operator which Node 12 doesn't like.

Yours looks like possibly some ruby issue but that's a bit of an unhelpful guess.

@nikolay-slavov
Copy link

I was having an issue specifically with symbol not found ExpoModulesPackageList

I had the same problem and upgrading the node version to 14 resolved the issue. Thanks!

@valascus
Copy link

valascus commented Jul 3, 2021

I knew this was happening. Solved it one hour after updating my unimodules. Tried to make a pull request, but too much burocracy.

at node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle , at line 97:

'require("expo-modules-autolinking")(process.argv.slice(1))',

switch the quotes like this:

"require('expo-modules-autolinking')(process.argv.slice(1))",

I've also made the changes mentioned in this commit about the unimodules implementation, but I don't know if this is needed for it to build, since I've found out the solution above later:

[ios][android] New autolinking implementation in TypeScript (#11593)

I guess it is the undocumented "new way" to implement unimodules?

@ivopr
Copy link
Author

ivopr commented Jul 3, 2021

well, when i changed OSes and tried jus now, it worked, maybe It got fixed in the meantime?
but anyway, thanks for the help guys

@ivopr ivopr closed this as completed Jul 3, 2021
@valascus
Copy link

valascus commented Jul 3, 2021

This is still a problem for windows users, at least.

@ivopr
Copy link
Author

ivopr commented Jul 3, 2021

I thought about it after closing, sorry, I'll leave it open, until the problem is fixed.

@jogacolhue
Copy link

jogacolhue commented Jul 3, 2021

I knew this was happening. Solved it one hour after updating my unimodules. Tried to make a pull request, but too much burocracy.

at node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle , at line 97:

'require("expo-modules-autolinking")(process.argv.slice(1))',

switch the quotes like this:

"require('expo-modules-autolinking')(process.argv.slice(1))",

I've also made the changes mentioned in this commit about the unimodules implementation, but I don't know if this is needed for it to build, since I've found out the solution above later:

[ios][android] New autolinking implementation in TypeScript (#11593)

I guess it is the undocumented "new way" to implement unimodules?

It works in Windows after making the change: "require('expo-modules-autolinking')(process.argv.slice(1))",
Thanks.

I also tested it in a React Native CLI app with react-native-unimodules.

@Albermonte
Copy link

Changin to "require('expo-modules-autolinking')(process.argv.slice(1))" works but that's not a solution, it's only a partial solution for local development but you can't modify that on a CI/CD

@tomhicks
Copy link

tomhicks commented Jul 5, 2021

@Albermonte you could use something like patch-package I think.

@byCedric
Copy link
Member

byCedric commented Jul 5, 2021

Hey all! I'm sorry for this issue and I can confirm this happens on Windows. I created a patch to fix this, I hope we can roll this out asap. If you absolutely need this to work, including on CI, you can work with patch-package until it is released.

You'll need to create a file in patches/@unimodules+react-native-adapter+6.3.1.patch, with this content:

diff --git a/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle b/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle
index aedcef3..1e5903e 100644
--- a/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle
+++ b/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle
@@ -94,7 +94,7 @@ class ExpoAutolinkingManager {
     String[] args = [
       'node',
       '--eval',
-      'require("expo-modules-autolinking")(process.argv.slice(1))',
+      'require(\'expo-modules-autolinking\')(process.argv.slice(1))',
       '--',
       command,
       '--platform',

Here is a short guide to set that up:

  1. Install patch-package as dev dependency
    yarn add --dev patch-package
  2. Add the postinstall hook to your package.json
    "scripts": { "postinstall": "patch-package" }
  3. Create folder patches
    mkdir patches
  4. Copy over the contents from above into:
    patches/@unimodules+react-native-adapter+6.3.1.patch
  5. Run yarn to apply the patch

If you commit the patch and changes in your package.json, this is applied in CI, classic build, and on EAS.

Hope this helps!

@joseocabarcas
Copy link

Hi! Thanks for the fix 💯 When do you plan to do the release fix to react-native-unimodules?

@byCedric
Copy link
Member

byCedric commented Jul 5, 2021

We are running into some complications, we will take a closer look at this part tomorrow and will release asap. When the fix is released, I'll post here again with the version that includes this.

@brkastner
Copy link

Upgrading node from v12 to v14 and applying that patch worked for me, thanks @valascus & @byCedric!

@byCedric
Copy link
Member

byCedric commented Jul 6, 2021

Patch has been released! Please use @unimodules/react-native-adapter@6.3.2 (latest). If you want to check your local version:

  • $ yarn why @unimodules/react-native-adapter
  • $ npm list @unimodules/react-native-adapter

It should be installed automatically, but if it doesn't make sure to regenerate your lockfile.

@Albermonte
Copy link

Still having an issue

> Task :unimodules-react-native-adapter:compileReleaseJavaWithJavac FAILED
/Users/runner/work/1/s/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
    mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                  ^
  symbol:   class ExpoModulesPackageList
  location: class ModuleRegistryAdapter
1 error

Developing works nice and builds but as soon as I try to build using AppCenter it fails
AppCenter Log: 1_Build.txt

@byCedric
Copy link
Member

byCedric commented Jul 6, 2021

Make sure to clean your cache, not only yarn or npm's cache but also the gradle cache.

To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

@kalvin807
Copy link

Make sure to clean your cache, not only yarn or npm's cache but also the gradle cache.

To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

I still ran into error when trying a similar workflow on a local MacOS machine

/.gradlew assembleDebug

node:internal/modules/cjs/loader:930
  throw err;
  ^

Error: Cannot find module 'expo-modules-autolinking'
Require stack:
- /Users/user/.gradle/daemon/6.8/[eval]
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)
    at Function.Module._load (node:internal/modules/cjs/loader:772:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/.gradle/daemon/6.8/[eval]' ]
}
> Task :unimodules-react-native-adapter:compileDebugJavaWithJavac FAILED
/Users/user/Workspace/ExpoIssue13475Fix/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
    mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                  ^
  symbol:   class ExpoModulesPackageList
  location: class ModuleRegistryAdapter
1 error

FAILURE: Build failed with an exception.

Steps I followed:

1. Run expo init ExpoIssue13475Fix --template expo-template-bare-minimum@42
2. Add "resolutions": { "@unimodules/react-native-adapter": "6.3.2" } to package.json
3. Run yarn install
4. Run ./gradlew assembleDebug at Android folder

yarn why @unimodules/react-native-adapter

=> Found "@unimodules/react-native-adapter@6.3.2"
info Reasons this module exists
   - "expo" depends on it
   - Hoisted from "expo#@unimodules#react-native-adapter"
   - Hoisted from "react-native-unimodules#@unimodules#react-native-adapter"
info Disk size without dependencies: "3.02MB"
info Disk size with unique dependencies: "3.7MB"
info Disk size with transitive dependencies: "9.26MB"
info Number of shared dependencies: 44

Machine info

Macbook Air M1
nodejs v16.4.2. (arm64)
java 1.8 (arm64)
Android SDK 29.0.3

@tkrajina
Copy link
Contributor

tkrajina commented Jul 7, 2021

I can confirm that it's still a problem. Similar configuration as @kalvin807

  • @unimodules/react-native-adapter@6.3.2
  • node v14.17.0
  • Macbookpro M1
  • cleared all the caches

Update: Tried it now on another Mac, cloned the project anew and the build fails with the same error.

@byCedric
Copy link
Member

byCedric commented Jul 7, 2021

Make sure to clean your cache, not only yarn or npm's cache but also the gradle cache.
To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

I still ran into error when trying a similar workflow on a local MacOS machine

/.gradlew assembleDebug

node:internal/modules/cjs/loader:930
  throw err;
  ^

Error: Cannot find module 'expo-modules-autolinking'
Require stack:
- /Users/user/.gradle/daemon/6.8/[eval]
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)
    at Function.Module._load (node:internal/modules/cjs/loader:772:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/.gradle/daemon/6.8/[eval]' ]
}
> Task :unimodules-react-native-adapter:compileDebugJavaWithJavac FAILED
/Users/user/Workspace/ExpoIssue13475Fix/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
    mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                  ^
  symbol:   class ExpoModulesPackageList
  location: class ModuleRegistryAdapter
1 error

FAILURE: Build failed with an exception.

Steps I followed:

1. Run expo init ExpoIssue13475Fix --template expo-template-bare-minimum@42
2. Add "resolutions": { "@unimodules/react-native-adapter": "6.3.2" } to package.json
3. Run yarn install
4. Run ./gradlew assembleDebug at Android folder

yarn why @unimodules/react-native-adapter

=> Found "@unimodules/react-native-adapter@6.3.2"
info Reasons this module exists
   - "expo" depends on it
   - Hoisted from "expo#@unimodules#react-native-adapter"
   - Hoisted from "react-native-unimodules#@unimodules#react-native-adapter"
info Disk size without dependencies: "3.02MB"
info Disk size with unique dependencies: "3.7MB"
info Disk size with transitive dependencies: "9.26MB"
info Number of shared dependencies: 44

Machine info

Macbook Air M1
nodejs v16.4.2. (arm64)
java 1.8 (arm64)
Android SDK 29.0.3

I think something is up with the dependencies in your project here. This error is slightly different from the original one and is not related to the fix we just sent out.

  • The original error is ReferenceError: expo is not defined, which is a result of the missing quotes on Windows.
  • Your error is Error: Cannot find module 'expo-modules-autolinking'. This might be caused by using a slightly older version of some dependency that doesn't include expo-modules-autolinking.

If you are using SDK 42, and have upgraded from an older version, you can try running expo upgrade again to validate the used dependencies. This might not catch everything, after that I would also double-check the versions manually using this list of dependencies with their versions. Your used dependencies should match the exact versions of that list.

Edit: As someone else pointed out, also make sure to run Node 14 (the current LTS) or higher (using even numbers)

Hope this helps!

@Albermonte
Copy link

I think something is up with the dependencies in your project here. This error is slightly different from the original one and is not related to the fix we just sent out.

  • The original error is ReferenceError: expo is not defined, which is a result of the missing quotes on Windows.
  • Your error is Error: Cannot find module 'expo-modules-autolinking'. This might be caused by using a slightly older version of some dependency that doesn't include expo-modules-autolinking.

If you are using SDK 42, and have upgraded from an older version, you can try running expo upgrade again to validate the used dependencies. This might not catch everything, after that I would also double-check the versions manually using this list of dependencies with their versions. Your used dependencies should match the exact versions of that list.

Edit: As someone else pointed out, also make sure to run Node 14 (the current LTS) or higher (using even numbers)

Hope this helps!

Running expo upgrade does nothing, instead, it downgrades react-native-unimodules from 0.14.3 to 0.14.2
The lock file still shows "@unimodules/react-native-adapter" "~6.3.1" even after expo upgrade under react-native-unimodules@~0.14.3 and expo@^42.0.0:
And of course the build is failing, you have more info in the log I posted yesterday

My yarn.lock file:

[...]
"@unimodules/react-native-adapter@~6.3.1":
  version "6.3.2"
  resolved "https://registry.yarnpkg.com/@unimodules/react-native-adapter/-/react-native-adapter-6.3.2.tgz#6dd549704d3fc7c729d657beff998f27a34f62a2"
  integrity sha512-jHrlGfIfs2GiPoDS6HttS5VZ4UmRSGiH1wArAJo7msAe0EACt6b9AR+CuxUPpK0d+DXv31iJzJxh9PYBzyA9Ag==
  dependencies:
    expo-modules-autolinking "^0.0.2"
    invariant "^2.2.4"
[...]
expo@^42.0.0:
  version "42.0.0"
  resolved "https://registry.yarnpkg.com/expo/-/expo-42.0.0.tgz#edf55d1bab197aa6e6883b4b593de2bb87f18e14"
  integrity sha512-m1/rPzh/Jgmy2Kx8I2wK7bjhMhwcp6oNJcYr3JqUphYYW4k+UgoKw/O5Dztt/Sy+vYAUH1tFAd+wLcMCmPUJbg==
  dependencies:
    "@babel/runtime" "^7.1.2"
    "@expo/metro-config" "^0.1.70"
    "@expo/vector-icons" "^12.0.4"
    "@unimodules/core" "~7.1.1"
    "@unimodules/react-native-adapter" "~6.3.1"
    babel-preset-expo "~8.4.0"
    cross-spawn "^6.0.5"
    expo-application "~3.2.0"
    expo-asset "~8.3.2"
    expo-constants "~11.0.1"
    expo-error-recovery "~2.2.0"
    expo-file-system "~11.1.3"
    expo-font "~9.2.1"
    expo-keep-awake "~9.2.0"
    fbemitter "^2.1.1"
    invariant "^2.2.2"
    md5-file "^3.2.3"
    pretty-format "^26.4.0"
    react-native-safe-area-context "3.2.0"
    serialize-error "^2.1.0"
    uuid "^3.4.0"
[...]
react-native-unimodules@~0.14.3:
  version "0.14.3"
  resolved "https://registry.yarnpkg.com/react-native-unimodules/-/react-native-unimodules-0.14.3.tgz#b84d050b554a790b9f79aeb534b8a8bbd27fbb2d"
  integrity sha512-FhAqztCacYvQwsx8FAOU+x3eywSFy3Tc9U86YovVWp86vz6066XU1SB/HPbAD+oiBJsB02yRPKxtYQT3CrOqnQ==
  dependencies:
    "@unimodules/core" "~7.1.1"
    "@unimodules/react-native-adapter" "~6.3.1"
    chalk "^2.4.2"
    expo-asset "~8.3.2"
    expo-constants "~11.0.1"
    expo-file-system "~11.1.3"
    expo-image-loader "~2.2.0"
    expo-modules-core "~0.2.0"
    find-up "~5.0.0"
    unimodules-app-loader "~2.2.0"
    unimodules-task-manager-interface "~6.2.0"

Manually changing those to "@unimodules/react-native-adapter" "~6.3.2" does nothing, build still fails on AppCenter CI

@kalvin807
Copy link

Make sure to clean your cache, not only yarn or npm's cache but also the gradle cache.
To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

I still ran into error when trying a similar workflow on a local MacOS machine

/.gradlew assembleDebug

node:internal/modules/cjs/loader:930
  throw err;
  ^

Error: Cannot find module 'expo-modules-autolinking'
Require stack:
- /Users/user/.gradle/daemon/6.8/[eval]
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)
    at Function.Module._load (node:internal/modules/cjs/loader:772:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/.gradle/daemon/6.8/[eval]' ]
}
> Task :unimodules-react-native-adapter:compileDebugJavaWithJavac FAILED
/Users/user/Workspace/ExpoIssue13475Fix/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
   mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                 ^
 symbol:   class ExpoModulesPackageList
 location: class ModuleRegistryAdapter
1 error

FAILURE: Build failed with an exception.

Steps I followed:

1. Run expo init ExpoIssue13475Fix --template expo-template-bare-minimum@42
2. Add "resolutions": { "@unimodules/react-native-adapter": "6.3.2" } to package.json
3. Run yarn install
4. Run ./gradlew assembleDebug at Android folder

yarn why @unimodules/react-native-adapter

=> Found "@unimodules/react-native-adapter@6.3.2"
info Reasons this module exists
   - "expo" depends on it
   - Hoisted from "expo#@unimodules#react-native-adapter"
   - Hoisted from "react-native-unimodules#@unimodules#react-native-adapter"
info Disk size without dependencies: "3.02MB"
info Disk size with unique dependencies: "3.7MB"
info Disk size with transitive dependencies: "9.26MB"
info Number of shared dependencies: 44

Machine info

Macbook Air M1
nodejs v16.4.2. (arm64)
java 1.8 (arm64)
Android SDK 29.0.3

I finally made it work by the following steps, it will help anyone who come across this. Thanks for everyone advice!

1. Set gradle version to 6.9
2. Remove .gradle folder under android
3. Clean && compile again

@rajeshde
Copy link

rajeshde commented Jul 8, 2021

Make sure to clean your cache, not only yarn or npm's cache but also the gradle cache.
To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

I still ran into error when trying a similar workflow on a local MacOS machine
/.gradlew assembleDebug

node:internal/modules/cjs/loader:930
  throw err;
  ^

Error: Cannot find module 'expo-modules-autolinking'
Require stack:
- /Users/user/.gradle/daemon/6.8/[eval]
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)
    at Function.Module._load (node:internal/modules/cjs/loader:772:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/.gradle/daemon/6.8/[eval]' ]
}
> Task :unimodules-react-native-adapter:compileDebugJavaWithJavac FAILED
/Users/user/Workspace/ExpoIssue13475Fix/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
   mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                 ^
 symbol:   class ExpoModulesPackageList
 location: class ModuleRegistryAdapter
1 error

FAILURE: Build failed with an exception.

Steps I followed:

1. Run expo init ExpoIssue13475Fix --template expo-template-bare-minimum@42
2. Add "resolutions": { "@unimodules/react-native-adapter": "6.3.2" } to package.json
3. Run yarn install
4. Run ./gradlew assembleDebug at Android folder

yarn why @unimodules/react-native-adapter

=> Found "@unimodules/react-native-adapter@6.3.2"
info Reasons this module exists
   - "expo" depends on it
   - Hoisted from "expo#@unimodules#react-native-adapter"
   - Hoisted from "react-native-unimodules#@unimodules#react-native-adapter"
info Disk size without dependencies: "3.02MB"
info Disk size with unique dependencies: "3.7MB"
info Disk size with transitive dependencies: "9.26MB"
info Number of shared dependencies: 44

Machine info

Macbook Air M1
nodejs v16.4.2. (arm64)
java 1.8 (arm64)
Android SDK 29.0.3

I finally made it work by the following steps, it will help anyone who come across this. Thanks for everyone advice!

1. Set gradle version to 6.9
2. Remove .gradle folder under android
3. Clean && compile again
  1. Upgraded Node to v14.17.3
  2. Upgraded Gradle to 6.9
  3. Removed .gradle folder
  4. Cleared all npm and react native caches
  5. Clean and Rebuild

Unfortunately, its still failing. Getting this below error.

Screenshot 2021-07-08 at 9 45 07 AM

@byCedric
Copy link
Member

byCedric commented Jul 9, 2021

Hi all, due to a mix of different underlying causes resulting in similar errors we are going to lock this thread. The error you will encounter for any of the underlying causes described below might look like this (comment):

Task :unimodules-react-native-adapter:compileReleaseJavaWithJavac FAILED
/Users/runner/work/1/s/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
    mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                  ^
  symbol:   class ExpoModulesPackageList
  location: class ModuleRegistryAdapter
1 error

Steps to fix it

  1. Remove node_modules and your lock file
    • npx rimraf node_modules yarn.lock package-lock.json
  2. Remove the gradle cache folder (.gradle) and clean your project.
    • cd android
    • npx rimraf .gradle
    • ./gradlew clean
  3. Install your Node dependencies
    • yarn install or npm install
  4. Validate your SDK 42 dependencies if the versions matches this list
    • expo upgrade 42 to rerun the SDK 42 upgrade (it should ask you this)
    • If any of the dependencies are changed, restart from step 1
  5. Validate if you have @unimodules/react-native-adapter@6.3.4 or later
    • yarn why @unimodules/react-native-adapter
    • or npm ls @unimodules/react-native-adapter
    • If you have an older version in a nested dependency, restart from step 1.
  6. Start the project

Known causes

These are some of the known underlying issues which are causing the error above.

  1. ReferenceError: expo is not defined on Windows only (comment)
    This issue was related to CMD removing double quotes (") in the command we run for auto-linking. It does NOT happen on MacOS or Linux and was fixed in PR [android] Escape Android autolinking script for windows #13494.

  2. Using Node 12 or lower (comment)
    This issue was related to the nullish coalescing operator (??) we used in the auto-linking code. This was fixed in PR [expo-modules-autolinking] Extend @tsconfig/node12 base config #13551. We still recommend using the current active LTS, which is Node 14.

  3. Fixing node modules, and running ./gradlew clean assembleRelease (1 command instead of 2)
    This issue is related to unexpected behavior with Gradle. It should be fixed in [unimodules][android] changed preBuild.dependsOn with quotes #13568. In the meantime, run these two commands separately.

Still running into issues?

If you tried everything from the steps to fix, and your issue isn't related to the underlying causes, please open a new issue.

@expo expo locked as resolved and limited conversation to collaborators Jul 9, 2021
@brentvatne
Copy link
Member

All of the issues that @byCedric summarized perfectly above are fixed in react-native-unimodules@0.14.5 and its dependency @unimodules/react-native-adapter@6.3.4. These versions include the fixes from the pull requests that he referenced.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.