“Unknown named module” error in react native

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 07:14:41

问题


I'm creating an app using react native but some imports raise the error from the title: "Unknown named module". This happens with two packages, react-native-material-design and react-native-db-models, so I suspect the problem isn't on the modules but in my setup.

I tried linking the packages with react-native link and repackaging the app using react-native run-android, but none of these solved this issue. I've looked up examples of imports on github, and even copying working code raises the same error.

I tried installing the modules using either yarn and npm. I tried with relative paths like ../../react-native-db-models. Didn't work!

This is how I import the modules:

import RNDBModel from 'react-native-db-models';

import { List, Button, Toolbar, } from 'react-native-material-design';

These are my project dependencies:

"dependencies": {
  "react": "15.4.1",
  "react-native": "0.39.2",
  "react-native-db-models": "^0.1.3",
  "react-native-material-design": "^0.3.7",
  "react-native-md-textinput": "^2.0.4",
  "react-native-vector-icons": "0.8.5",
  "react-redux": "^5.0.1",
  "redux": "^3.6.0",
  "redux-logger": "^2.7.4"
},

If React/React Native is incompatible with these modules, how do I figure out which version should I use? Maybe the error has nothing to do with imports and has something to do with my project?


回答1:


The package server started by react-native start seems to have a cache of the node modules. Stopping and restarting the server solved the issue.

Always restart your react server after installing modules!




回答2:


A quick check on the package's repository shows 'List' module is no longer available. Here is a link to why it was removed.

So, you will have to remove 'List' module from your import:

import { Button, Toolbar, } from 'react-native-material-design';


来源:https://stackoverflow.com/questions/41232861/unknown-named-module-error-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!