Cli: TypeError: Cannot convert undefined or null to object when building for android

Created on 24 Jul 2019  路  11Comments  路  Source: react-native-community/cli

Environment

System:
OS: Windows 10
CPU: (6) x64 Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
Memory: 8.59 GB / 15.94 GB
Binaries:
Node: 10.15.0 - C:\Program Files\nodejs\node.EXE
npm: 6.10.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

Description

After updating app react-native from 0.57.8 to 0.60.4 and all other libraries i got the following issue:

`
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • Where:
    Script 'D:\VisualStudio Code\AppName\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 190

  • What went wrong:
    A problem occurred evaluating settings 'AppName'.

    Unable to determine the current character, it is not a string, number, array, or object

    The current character read is 'T' with an int value of 84
    Unable to determine the current character, it is not a string, number, array, or object
    line number 1
    index number 0
    TypeError: Cannot convert undefined or null to object at Function.keys () at isValidRNDependency (D:\VisualStudio Code\AppName\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\config\config.js:13:109) at Object.keys.forEach.item (D:\VisualStudio Code\AppName\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\config\config.js:20:10) at Array.forEach () at filterConfig (D:\VisualStudio Code\AppName\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\config\config.js:19:38) at Object.func (D:\VisualStudio Code\AppName\node_modules\react-native\node_modules\@react-native-community\cli\build\commands\config\config.js:31:32) at Command.handleAction (D:\VisualStudio Code\AppName\node_modules\react-native\node_modules\@react-native-community\cli\build\cliEntry.js:160:21) at Command.listener (D:\VisualStudio Code\AppName\node_modules\commander\index.js:315:8) at Command.emit (events.js:182:13) at Command.parseArgs (D:\VisualStudio Code\AppName\node_modules\commander\index.js:651:12)
    `

Error occurs while running any gradle command lik for example ./gradlew clean or ./graldew assembleDebug

Reproducible Demo

  1. Upgrade project libraries and react-native from 0.57.8 to 0.60.4 and use migration to androidX
  2. Run any gradle command

package.json file:

{
"name": "AppName",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/geolocation": "^1.4.2",
"@react-native-community/netinfo": "^4.1.3",
"geolib": "^3.0.4",
"react": "^16.8.6",
"react-native": "0.60.4",
"react-native-admob-dfp": "^2.0.0-beta.3.9",
"react-native-android-location-enabler": "^1.2.0",
"react-native-app-settings": "^2.0.1",
"react-native-background-fetch": "^2.6.1",
"react-native-background-geolocation": "^3.0.9",
"react-native-device-info": "^2.3.0",
"react-native-firebase": "^5.5.5",
"react-native-geolocation-service": "^3.0.0",
"react-native-gesture-handler": "^1.3.0",
"react-native-image-pan-zoom": "^2.1.11",
"react-native-maps": "^0.25.0",
"react-native-navigation-directions": "^1.0.3",
"react-native-permissions": "^1.2.0",
"react-native-phone-call": "^1.0.9",
"react-native-popup-dialog": "^0.18.3",
"react-native-responsive-screen": "^1.2.2",
"react-native-screens": "^1.0.0-alpha.23",
"react-native-side-drawer": "^1.1.9",
"react-native-spinkit": "^1.4.0",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^9.5.3",
"react-native-swipe-gestures": "^1.0.3",
"react-navigation": "^3.11.1",
"react-navigation-transitions": "^1.0.11",
"realm": "^3.0.0-beta.2"
},
"devDependencies": {
"@babel/core": "7.5.5",
"@babel/runtime": "7.5.5",
"@react-native-community/eslint-config": "0.0.3",
"babel-jest": "24.8.0",
"babel-plugin-transform-remove-console": "6.9.4",
"eslint": "6.1.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.0",
"react-test-renderer": "16.8.6"
},
"jest": {
"preset": "react-native"
}
}

bug

Most helpful comment

Same error here. Happens when I try to exclude a dependency from autolinking.

This is my react-native.config.js:

module.exports = {
  dependencies: {
    'react-native-background-location': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink
      },
    },
  },
}

All 11 comments

Same error i am getting

Same error here. Happens when I try to exclude a dependency from autolinking.

This is my react-native.config.js:

module.exports = {
  dependencies: {
    'react-native-background-location': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink
      },
    },
  },
}

@N1ghtly
Removing that file fixes my problem yes... That is weird, but thank you
I'll be removing my react-native.config.js
Until I find out more.

Unfortunately I can't remove that file because i need that module to be excluded from autolinking...

This needs to be investigated. This seems to be a problem with parsing react-native.config.js. I will take a look.

Just check do you have any empty space in dependencies, I was having empty space. now it works

Just check do you have any empty space in dependencies

@affanhashone what do you mean by that?

I edited the file directly in node_modules and added && everywhere there could be an or Array.length call:

node_modules/@react-native-community/cli/build/commands/config/config.js

function isValidRNDependency(config) {
  return Object.keys(config.platforms).filter(key => Boolean(config.platforms[key])).length !== 0 
  || config.hooks && Object.keys(config.hooks).length !== 0 
  || config.assets && config.assets.length !== 0 
  || config.params && config.params.length !== 0;
}

And it builds/cleans correctly

@stevelacy works. I previously edited my dependency config to include all the parameters they're trying to access, which works as well.

Mind sending a PR with that?

@thymikee this can be closed, I think.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mauricioscotton picture mauricioscotton  路  3Comments

thymikee picture thymikee  路  4Comments

tallpants picture tallpants  路  4Comments

lucasbento picture lucasbento  路  3Comments

jchook picture jchook  路  4Comments