brunolemos / react-native-web-monorepo

Code sharing between iOS, Android & Web using monorepo
https://dev.to/brunolemos/tutorial-100-code-sharing-between-ios-android--web-using-react-native-web-andmonorepo-4pej
865 stars 175 forks source link

cannot find ./index #44

Closed alzalabany closed 3 years ago

alzalabany commented 4 years ago

enviroment: Windows 10 latest yarn, ts

git clone repo.. cd yarn && yarn workspace mobile start

bundling failed: Error: Unable to resolve module ./app.json from C:\workspace\react-native-web-monorepo\index.js: The module ./app.json could not be found from C:\workspace\react-native-web-monorepo\index.js. Indeed, none of these files exist:

hosseinmd commented 4 years ago

this error occurs when you use react-native bundle
use this react-native bundle --platform android --dev false --entry-file packages/mobile/index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

--entry-file is defined packages/mobile/index.js instead of index.js

the bundle is not recommended.

gko commented 4 years ago

Try changing the path to index within MainApplication.java in packages/mobile/android/app/src/main/java/:

@Override
protected String getJSMainModuleName() {
    return "packages/mobile/index";
}
hosseinmd commented 4 years ago

Changing the index path is not the right way, because every platform has a different config in the index file.

gko commented 4 years ago

@hosseinmd agree, but I also stumbled upon this problem and didn't find other solution. (react-native bundle didn't work)

hosseinmd commented 4 years ago

I think you have a problem in build.Gradle. Please check this.

project.ext.react = [
    entryFile: "packages/mobile/index.js",
    root: "../../../../",
]
gko commented 4 years ago

@hosseinmd I made a small PR fixing this issue. Tested on android and ios emulators on macOS Catalina

/cc @brunolemos