簡體   English   中英

[React-Native]不變違規:元素類型無效

[英][React-Native]Invariant Violation: Element type is invalid

當我運行一些開玩笑的測試用例時,發生了此錯誤,並且似乎是內部的node_module錯誤,如何解決此問題?

它似乎與react-test-rendererfbjs

錯誤

不變違規:元素類型無效:預期為字符串(對於內置組件)或類/函數(對於復合組件),但得到:對象。 您可能忘記了從定義文件中導出組件。

  at invariant (node_modules/fbjs/lib/invariant.js:44:7)
  at ReactCompositeComponentWrapper.instantiateReactComponent [as _instantiateReactComponent] (node_modules/react-test-renderer/lib/instantiateReactComponent.js:77:44)
  at ReactCompositeComponentWrapper.performInitialMount (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:367:16)
  at ReactCompositeComponentWrapper.mountComponent (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:258:13)
  at Object.mountComponent (node_modules/react-test-renderer/lib/ReactReconciler.js:46:29)
  at mountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:55:27)
  at ReactTestReconcileTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:140:12)
  at batchedMountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:69:23)
  at ReactDefaultBatchingStrategyTransaction.perform (node_modules/react-test-renderer/lib/Transaction.js:140:12)
  at Object.batchedUpdates (node_modules/react-test-renderer/lib/ReactDefaultBatchingStrategy.js:62:20)

package.json

{
  "private": true,
  "scripts": {
    "web": "roadhog server",
    "build-web": "cross-env NODE_ENV=production roadhog build",
    "start": "react-native start",
    "ios": "cross-env NODE_ENV=development node themes/theme.rn.config.js && react-native run-ios",
    "android": "cross-env NODE_ENV=development node theme/theme.rn.config.js && react-native run-android",
    "lint": "eslint --ext .js src test",
    "precommit": "npm run lint && npm run test",
    "test": "cross-env NODE_ENV=test jest --config .jest.config.json --no-cache --debug"
  },
  "engines": {
    "install-node": "6.9.2"
  },
  "theme": "./themes/theme.web.config.js",
  "dependencies": {
    "antd-mobile": "^1.0.8",
    "babel-runtime": "^6.9.2",
    "dva": "^1.2.1",
    "lodash": "^4.17.4",
    "moment": "^2.18.1",
    "rc-form": "^1.3.0",
    "react": "15.4.2",
    "react-dom": "15.4.2",
    "react-native": "0.42.3",
    "react-native-chart": "^1.0.8-beta",
    "react-native-gesture-password": "^0.2.0",
    "react-native-scrollable-tab-view": "^0.7.4",
    "react-native-smart-gesture-password": "^2.1.0",
    "react-navigation": "^1.0.0-beta.7",
    "recharts": "^0.21.2",
    "socket.io-client": "^1.7.3"
  },
  "devDependencies": {
    "babel-eslint": "^7.1.1",
    "babel-jest": "^19.0.0",
    "babel-plugin-dva-hmr": "^0.3.2",
    "babel-plugin-import": "^1.1.1",
    "babel-plugin-transform-runtime": "^6.9.0",
    "babel-preset-react-native": "^1.9.1",
    "cross-env": "^4.0.0",
    "eslint": "^3.12.2",
    "eslint-config-airbnb": "^13.0.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^2.2.3",
    "eslint-plugin-react": "^6.8.0",
    "expect": "^1.20.2",
    "husky": "^0.13.3",
    "jest": "^19.0.2",
    "less-vars-to-js": "^1.1.2",
    "postcss-pxtorem": "^4.0.0",
    "react-test-renderer": "15.4.2",
    "redbox-react": "^1.3.2",
    "roadhog": "^0.6.0-beta1"
  }
}

我花了好一會兒才知道這一點……太明顯了。 我正在使用react-test-renderer來測試index.ios.js渲染正確。 但是在我的index.ios.js中,我實際上沒有導出任何React組件,所以...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM