question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot get property 'packageName' on null object

See original GitHub issue

Moving from #537

Environment

System: OS: macOS 10.15 CPU: (4) x64 Intel® Core™ i5-6267U CPU @ 2.90GHz Memory: 2.70 GB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.8.0 - /var/folders/xh/gcxkb1qx2rd3fmqz5vxrs2lh0000gn/T/yarn–1567321836628-0.386672585258681/node Yarn: 1.17.3 - /var/folders/xh/gcxkb1qx2rd3fmqz5vxrs2lh0000gn/T/yarn–1567321836628-0.386672585258681/yarn npm: 6.10.3 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 Android SDK: API Levels: 28 Build Tools: 28.0.3 IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 10.3/10G8 - /usr/bin/xcodebuild

Description

Can’t get react-native 0.61 to work on a monorepo on Android. Build fails with the error: Cannot get property 'packageName' on null object. iOS works as expected.

Running yarn react-native config returns this result:

{
  "root": "/Users/user/Projects/react-native-web-monorepo",
  "reactNativePath": "/Users/user/Projects/react-native-web-monorepo/node_modules/react-native",
  "dependencies": {},
  "commands": [],
  "assets": [],
  "platforms": {},
  "haste": {
    "providesModuleNodeModules": [],
    "platforms": []
  },
  "project": {}
}

Using nohoist or installing react-native inside packages/mobile instead of the root is not an option because that causes a range of other issues.

Reproducible Demo

Branch rn61 with error: https://github.com/brunolemos/react-native-web-monorepo/tree/rn61 Branch master working, with workarounds: https://github.com/brunolemos/react-native-web-monorepo

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
mllwcommented, Oct 16, 2019

@brunolemos

I did have to add react-native dependency to the root package.json and create a react-native.config.js though. Not a big deal but hopefully that gets fixed, this workaround was not necessary on <= 0.59.

I have tried your repository and I don’t think this is a correct way to run things.

The problem that appears here is that you have set sourceDir to be <root>/packages/mobile/android.

The CWD is: <root>/packages/mobile at the time of running your script (via yarn workspace mobile).

As a result, React Native CLI tries to look for Android files inside <root>/packages/mobile/packages/mobile/android, which produces null and as a result, makes Android files check for packageName of null.

Right now, the paths are relative to the CWD. Maybe they should be relative to the location of the configuration file, but that would be a change.

Moving from #537

Environment

System: OS: macOS 10.15 CPU: (4) x64 Intel® Core™ i5-6267U CPU @ 2.90GHz Memory: 2.70 GB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.8.0 - /var/folders/xh/gcxkb1qx2rd3fmqz5vxrs2lh0000gn/T/yarn–1567321836628-0.386672585258681/node Yarn: 1.17.3 - /var/folders/xh/gcxkb1qx2rd3fmqz5vxrs2lh0000gn/T/yarn–1567321836628-0.386672585258681/yarn npm: 6.10.3 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 Android SDK: API Levels: 28 Build Tools: 28.0.3 IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 10.3/10G8 - /usr/bin/xcodebuild

Description

Can’t get react-native 0.61 to work on a monorepo on Android. Build fails with the error: Cannot get property 'packageName' on null object. iOS works as expected.

Running yarn react-native config returns this result:

{
  "root": "/Users/user/Projects/react-native-web-monorepo",
  "reactNativePath": "/Users/user/Projects/react-native-web-monorepo/node_modules/react-native",
  "dependencies": {},
  "commands": [],
  "assets": [],
  "platforms": {},
  "haste": {
    "providesModuleNodeModules": [],
    "platforms": []
  },
  "project": {}
}

Using nohoist or installing react-native inside packages/mobile instead of the root is not an option because that causes a range of other issues.

Reproducible Demo

Branch rn61 with error: https://github.com/brunolemos/react-native-web-monorepo/tree/rn61 Branch master working, with workarounds: https://github.com/brunolemos/react-native-web-monorepo

I modify node_modules/@react-native-community/cli-platform-android/native_modules.gradle at line 157 cmdProcess = Runtime.getRuntime().exec(command) change to cmdProcess = Runtime.getRuntime().exec(command,null,new File(System.getProperty(“user.dir”)).getParentFile()) work OK

5reactions
Jyrno42commented, Sep 24, 2019

Having same issue with an example app of a package which contains no native modules.

E: Adding this to react-native.config.js resolved the issue:

	project: {
		ios: {
			project: 'example/ios/Example.xcodeproj'
		},
		android: {
			sourceDir: 'example/android'
		}
	},
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot get property 'packageName' on null object #835 - GitHub
The statement json["project"]["android"]["packageName"] clearly assumes that every project will have android and packageName present. However, ...
Read more >
react native - Cannot get property 'packageName' on null object
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with...
Read more >
Cannot Get Property "Name" On Null Object - Oracle Support
Cannot get property name on null object .Java.lang null pointer exception. ... 2. Click on the rule set name . The first screen...
Read more >
react-native Cannot get property 'packageName' on null object
react-native打包安卓apk的时候,报错Cannot get property 'packageName' on null object完全没有头绪,研究了半天才发现竟然是因为package.json ...
Read more >
react-native报错Cannot get property packageName on null ...
为了本站的长期运营,请将本站广告加入广告屏蔽器的白名单,谢谢您的支持! —fly63前端网.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found