首页 > 解决方案 > TypeError: undefined is not an object (evaluate '_reactNative.Stylesheet.create') in react native

问题描述

我正在用 react native 制作一个项目,并且我已经安装了它的所有依赖项,但是当我运行它显示的代码时

TypeError: undefined is not an object (evaluating '_reactNative.Stylesheet.create')

连同下面的这个

  • node_modules/react-native/Libraries/LogBox/LogBox.js:148:8 in registerError

  • node_modules/react-native/Libraries/LogBox/LogBox.js:59:8 in errorImpl

  • node_modules/react-native/Libraries/LogBox/LogBox.js:33:4 in console.error

  • node_modules/expo/build/environment/react-native-logs.fx.js:27:4 错误

  • node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException

  • node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException

  • node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError

  • ErrorUtils.setGlobalHandler$argument_0 中的 node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:9:32

  • tryCatch 中的 node_modules/regenerator-runtime/runtime.js:63:36

  • node_modules/regenerator-runtime/runtime.js:293:29 在调用

  • tryCatch 中的 node_modules/regenerator-runtime/runtime.js:63:36

  • 调用中的 node_modules/regenerator-runtime/runtime.js:154:27

  • PromiseImpl.resolve.then$argument_0 中的 node_modules/regenerator-runtime/runtime.js:164:18

  • tryCallOne 中的 node_modules/react-native/node_modules/promise/setimediate/core.js:37:13

  • setImmediate$argument_0 中的 node_modules/react-native/node_modules/promise/setimmediate/core.js:123:24

  • _callTimer 中的 node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14

  • _callImmediatesPass 中的 node_modules/react-native/Libraries/Core/Timers/JSTimers.js:181:14

  • node_modules/react-native/Libraries/Core/Timers/JSTimers.js:441:30 in callImmediates

  • __callImmedates 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:387:6

  • __guard$argument_0 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6

  • __guard 中的 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10

  • node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:4 在flushedQueue

  • [本机代码]:flushedQueue 中的 null
  • [本机代码]:invokeCallbackAndReturnFlushedQueue 中的 null

起初它谈到了我修复的一个函数,但我不明白它在哪里引用未定义的对象,如果有人能找到它正在谈论的文件或函数,那就太好了。

标签: javascriptreact-nativenpm

解决方案


请尝试这样的事情

const styles = StyleSheet.create({ 
  _container: { 
    flex: 1, 
    backgroundColor: 'blue', 
    alignItems: 'center', 
    justifyContent: 'center' 
  }, 
  get container() { 
    return this._container; 
  }, 
  set container(value) { 
    this._container = value; 
  }, 
});

推荐阅读