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

Replace alias in dependencies? #25

Open
michaelBenin opened this issue Mar 22, 2015 · 6 comments
Open

Replace alias in dependencies? #25

michaelBenin opened this issue Mar 22, 2015 · 6 comments

Comments

@michaelBenin
Copy link

I've been doing some testing on using aliasify to replace requires of underscore for lodash. I've enabled verbose to be true. I've ran into an issue where in Backbone it still requires underscore instead of lodash.

See the output below:

Output:

aliasify - /Users/michaelbenin/Projects/node-startup/apps/about/about_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/home/home_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/links/links_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/login/login_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/search/search_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/searchquery/searchquery_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/signup/signup_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/topics/topics_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/users/users_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/home/home_sub_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/nav/nav_view.js: replacing underscore with lodash
aliasify - /Users/michaelbenin/Projects/node-startup/apps/footer/footer_view.js: replacing underscore with lodash
>> Error: Cannot find module 'underscore' from '/Users/michaelbenin/Projects/node-startup/node_modules/backbone'

Configuration:

var aliasify = require('aliasify');

var aliasifyConfig = {
  aliases: {
    underscore: 'lodash'
  },
  verbose: true
};

// in my browserify file:

b.transform(aliasify, aliasifyConfig);
@anthonyhastings
Copy link

I'm having an almost identical problem but with trying to use Exoskeleton with backbone.nativeview. My problem is the same as yours though; Aliasify will cycle through my SOURCE FILES, but ignores looking in the dependencies that I have in my node_modules folder.

[10:07:42] Starting 'scripts'...
aliasify - /var/www/planner/app/static/js/src/main.js: replacing backbone with exoskeleton
Browserify Failed: Cannot find module 'backbone' from '/var/www/planner/app/static/node_modules/backbone.nativeview'
[10:07:42] 'scripts' errored after 854 ms

How do we make Aliasify cycle not just our source files, but the dependencies loaded from node_modules?

@ball-hayden
Copy link

This is not an aliasify issue, but a browserify one.

A transform is only applied to source files, not node_modules
If you wish to apply aliasify to all files, you should run it as a "global transform"

(I had the same problem, and found this out via browserify/browserify#501)

@anthonyhastings
Copy link

Yes you seem to be correct. Whenever specifying the transform, we seem to need to set global i.e.

    bundle.transform('aliasify', {
        aliases: {
            'backbone': 'exoskeleton'
        },
        verbose: true,
        global: true
    })

Apologies for the confusion, I guess that's down to me being unclear as to how transforms work. There's a lot of the Browserify documents to digest!

@tj
Copy link

tj commented May 8, 2016

Seems to not work for me, I have:

  "browserify": {
    "transform": [
      ["aliasify", {
        "global": true,
        "debug": true,
        "aliases": {
          "react": "preact-compat",
          "react-dom": "preact-compat"
        }
      }]
    ]
  },

and still get plenty of:

Error: Cannot find module 'react' from '/Users/tj/dev/src/github.com/tj/vitals/client/node_modules/react-router/lib'
Error: Cannot find module 'react' from '/Users/tj/dev/src/github.com/tj/vitals/client/node_modules/react-router/lib'

I tried adding the package.json config as mentioned in the readme, but that seems to have no effect. Any suggestions?

@michaelBenin
Copy link
Author

This might help with defining global transforms in the package.json:

browserify/browserify#566

@tj
Copy link

tj commented May 8, 2016

Breaks on const's, seems like it's working now otherwise!

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

4 participants