Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Packager] require('react-native') must be assigned to React #1479

Closed
alinz opened this issue Jun 1, 2015 · 5 comments
Closed

[Packager] require('react-native') must be assigned to React #1479

alinz opened this issue Jun 1, 2015 · 5 comments
Assignees
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@alinz
Copy link

alinz commented Jun 1, 2015

By accident I have assigned require('react-native') to a variable other than React and It failed to execute. hmmm...

This code works fine

var React = require('react-native');

var {
  Component,
  View
} = React;

class MyApp extends Component {
  render() {
    return (
      <View></View>
    );
  }
}

module.exports = MyApp;

By this one doesn't

var Test = require('react-native');

var {
  Component,
  View
} = Test;

class MyApp extends Component {
  render() {
    return (
      <View></View>
    );
  }
}

module.exports = MyApp;

Here's what I got as an error:
screen shot 2015-06-01 at 1 47 47 pm

@brentvatne brentvatne changed the title require('react-native') must be assigned to React [Packager] require('react-native') must be assigned to React Jun 1, 2015
@jtremback
Copy link
Contributor

👍

@alinz
Copy link
Author

alinz commented Jun 1, 2015

After some digging I found that JSX transformer is the root cause.

Here's an example:

var Test = require('react-native');
...

render() {
    return (
        <View></View>
    );
}

is compiles into

return (
    React.createElement(View, null)
);

even though I required react-native to Test, JSX compiler doesn't really care and uses React object to create the View element.

@brentvatne
Copy link
Collaborator

What use case do you have for using a name other than React? While this isn't ideal I don't think it is really a big issue either 😄 cc. @frantic.

@alinz - If you want to look into it and submit a PR that would be great.

@alinz
Copy link
Author

alinz commented Jun 1, 2015

@brentvatne I don't have any! I wish I had one! ;)
I don't know whether this PR would be beneficial for anyone, but challenge accepted! 👍

@sophiebits
Copy link
Contributor

We don't intend to support this in the JSX transformer, sorry. We require that you have React in scope.

@facebook facebook locked as resolved and limited conversation to collaborators Jun 1, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants