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

Cannot manage to alias react/addons to react #14

Closed
TheLudd opened this issue Sep 10, 2014 · 5 comments
Closed

Cannot manage to alias react/addons to react #14

TheLudd opened this issue Sep 10, 2014 · 5 comments

Comments

@TheLudd
Copy link

TheLudd commented Sep 10, 2014

I am experementing a bit with react, browserify and aliasify and I have these wishes:

  • I want to bundle all code written by me into a single file
  • I want to bundle all 3rd party dependencies (react, react-router, lodash etc) into separate files, one for each lib, to maximize caching possibilities

I have managed to do the things described above but I ran into this specific situation:

In some places of my code I want to use react with addons and as such require it like this: var React = require('react/addons). I don't do this in all parts of my code and it is not done in 3rd party dependencies such as react-router.

I tried to solve this situation with aliasify like this for all my extrnal modules

var b = browserify()
var aliasTransform = aliasify.configure({
  aliases: {
    react: 'react/addons'
  }
})
b.transform(aliasTransform)
b.external('react') // have also tried 'react/addons'
b.require('react-router')
b.bundle()

What happens when I load my page is that I get the error Cannot find module 'react' originating from the react-router module.

Should it be possible to do what I am trying to do?

More general question on stackoverflow

@jwalton
Copy link
Contributor

jwalton commented Sep 16, 2014

I'm not familiar with react, but;

With or without aliasify installed, when you try to require "react/addons", browserify (or node.js server side, for that matter) will try to find a module called react, and then will try to include the addons.js or addons/index.js file from the react module. Looking at the react project, I don't see such a file.

@TheLudd
Copy link
Author

TheLudd commented Sep 16, 2014

Well, I am not sure how the project is built but if you install it with npm, you will find node_modules/react/addons.js in your folder.

@jwalton
Copy link
Contributor

jwalton commented Nov 17, 2014

Hey @TheLudd, have a look at #17 and see if the suggestions there fix things for you. :)

@TheLudd
Copy link
Author

TheLudd commented Nov 17, 2014

I have managed to produce another solution for this. A "shim" if that is the correct term. Looks like this:

  1. Browserify react/addons into it's own file
  2. Create my own file (called shim) only containing this: module.exports = require('react/addons');
  3. Browserify my shim and use the expose option, exposing it as react

Now, either if react or react/addons is required I get react/addons

Should the issue be closed? My problem is solved but perhaps this is still an issue in the eyes of aliasify.

@jwalton
Copy link
Contributor

jwalton commented Nov 17, 2014

I'll close this one, as I think 17 is essentially the same issue. Glad you found a workaround. :)

@jwalton jwalton closed this as completed Nov 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants