Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Support for npm installed packages on the browser #846

brettz9 opened this Issue · 3 comments

2 participants


Npm does not restrict itself to Node.js or Node.js only modules, so it can be useful for sharing modules for the browser (though it has what seems to me to be an unnecessary restriction against upper-case characters in module names). Might requirejs either allow:

  1. Full Ajax checks for package.json and resolution of the file referenced in its "main" property.
  2. Expect a convention such as /node_modules/<pkg>/<pkg>.js or /node_modules//index.js, or /node_modules/<pkg>/main.js so that Ajax can be avoided. (Or maybe fallback to the Ajax if it is not found.)

Of course, it would be ideal if the same code written for the browser in this manner could still work in Node as well.


It is best if either the package manager or a command line helper tool either creates an adapter module so that 1) 'example.js' points to the 'main' module in the 'example' directory, or 2) enters a paths or packages config in a requirejs config block. It could then also convert the modules to amd format for example too.

volo does path 1) create an adapter module. If the project that volo installs into is an AMD project, it will also try to convert any node/cjs modules to amd format.

Unfortunately, npm as-is lays out code that is not very helpful for dynamic loading for the browser.

A loader in the browser should also not try to do http requests for a package.json as that will lead to 404s in some cases, and it is extra requests that can be avoided by laying out the files and directories, and creating an adapter module once. JSON fetching is also subject to CORS rules, which leads to support requests.

So no plans to add functionality in this area, as the right solution is better command line tools for project setup.

The "same module system in node and browser" will likely have to wait until ECMAScript modules land.

@jrburke jrburke closed this

As far as ES6 modules and command line helpers, this looks interesting: .

Despite this, I still think it would be useful to have something for on-the-fly loading, as it is very valuable to debug without an intermediate step of using the command line, even if just one command. I am therefore interested to take a closer look at/try out .

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.