Aleksei Anatskii
Aleksei Anatskii

Reputation: 307

Can r.js resolve dependency installed with npm?

I've install r.js from npm with npm install requirejs.

I'm expecting this function to produce some output to console, while running it with node main.js:

// main.js
var requirejs = require('requirejs');

requirejs.optimize({
    baseUrl: STATIC_PATH + 'js',
    nodeRequire: require,
    include: ['a', 'b'],
    out: function(text) {
        console.log(text);
    }
});

And modules A and B are defined as following:

// a.js

define(['b'], function($) {
    console.log('A');
});

I know from requirejs docs that it could handle modules installed with npm, so here I'm trying to use jquery that was previously installed with npm install jquery

// b.js

define(['jquery'], function($) {
    console.log('B', $);
});

But when I'm running main.js I've got an error, which states that r.js could not find file named jquery.js.

So basically my question is am I missing something or it isn't possible to make r.js lookup for modules installed via npm?

UPDATE: Here is github repo with MCVE — https://github.com/sintell/rjs_mcve

Upvotes: 2

Views: 201

Answers (1)

Evan Davis
Evan Davis

Reputation: 36592

Require expects the AMD module syntax, but NPM uses CommonJS. You could tell require (using the paths config) where to find the modules, but they still wouldn't be compatible in many cases.

Upvotes: 1

Related Questions