Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unknown named module" error in react native

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?

like image 891
Marco Lavagnino Avatar asked Dec 19 '16 23:12

Marco Lavagnino


1 Answers

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!

like image 66
Marco Lavagnino Avatar answered Sep 21 '22 23:09

Marco Lavagnino