2

I saw code like var Animated = require('Animated') in react-native source code. But how can this be resolved without a path ?
My guess is that will be preprocessed by the packager by something like registering and I would like to do this in my own project. But there seems to be no document for react-native's packager , and I can't find the source code where this "registering" happen.

Nick Allen
  • 1,647
  • 14
  • 20

2 Answers2

2

I think I find it! Just add @providesModule moduleName in the file's comment in the header , look into issue 896 for detail.

Nick Allen
  • 1,647
  • 14
  • 20
0
import {
  Animated,
  View,
  Text,
} from 'react-native';

i can't catch what you said.but i post the above snippet how i used.

李振纲
  • 372
  • 3
  • 11
  • 'react-native' is a npm package so you can import from it without path. But in most case we just want to import a js file in our own project. which may look like import {...} from {../../../core/logic/whatever}. And once you move the target to somewhere else, everything is broken. – Nick Allen May 25 '16 at 08:55
  • how about this var Animated = require('../node_modules/react-native/Libraries/Animated/src/Animated.js') – 李振纲 May 27 '16 at 02:56
  • What I am asking is how to use that like require('Animated') without a path. That is exactly how react-native source code do. Something happen because their internal tool haste. – Nick Allen May 27 '16 at 03:02
  • [some relation](http://stackoverflow.com/questions/33143147/requiring-modules-in-react-native) wait for your resolution. – 李振纲 May 27 '16 at 03:08
  • I am still trying to figure out how `haste` work, there is nearly no document at all . – Nick Allen May 27 '16 at 03:13