Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Using .alias for relative requires #184

Closed
jed opened this Issue · 5 comments

3 participants

@jed

I'm trying to create localized browserify bundles, and my code looks something like this:

/build.js

// build the english version
var b = browserify()
b.require("./locales/en")
b.alias("locale","./locales/en")
b.addEntry("app.js")

/app.js

var locale = require("locale")
alert(locale.hello)

/locales/en.js

module.exports = {
  hello: "Hello!"
}

but I keep getting errors like Error: Cannot find module: "locale" from directory [blah]... Are relative directories not supported for .alias, or am I doing it wrong?

@substack
Owner

Aliases are a bit screwy in how they map paths to other paths. Try doing b.alias('/node_modules/locale/index.js', '/locales/en')

@jed
jed commented

I'll try that. Thanks, @substack.

@jed
jed commented

@substack,

i've boiled this down to the smallest test case possible, but still can't get it to work. one of the following always happens:

  1. compilation fails and i get Error: Cannot find module: "locale" from directory "/Users/jed/Desktop/3038799" while processing file /Users/jed/Desktop/3038799/src.js
  2. compilation succeeds and i get the run-time error Error: Cannot find module 'locale'

would love if you could take a look at this. here's a quick one liner to test it.

git clone git://gist.github.com/3038799.git && cd 3038799 && npm i && npm test
@wachunga

I would love a fix for this too. Currently I have to include the full path, which is annoying for things like js/lib/lib-1.8.21.min.js.

As far as I can tell, .alias() only works for npm modules. Using it for local dependencies never works because there is no entry for an aliased module in require.modules.

@substack
Owner

There are no aliases in v2 but you can do a similar kind of thing with .expose() across multiple bundles.

@substack substack closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.