RequireJS in node does not work for dependencies with plugins (e.g. with use.js)

To separate AMD modules between browser and node, I use RequireJS in both places (see RequireJS in Node ).

server / dataDao.js:

var requirejs = require('requirejs');
var dataDao = module.exports = {};

requirejs(['client/resource'], function (Resource) {
   ...
});

client / resource.js:

define(['underscore'], function (_) {
  ...
});

This usually works fine if the common module does not contain any dependencies that do not work on the server.

I would like to introduce use.js to avoid the manual packaging of non-AMD compatible libraries such as underscores. To do this, I must prefix the listed dependencies with use!(to launch the use plugin in RequireJS).

client / resource.js:

define(['use!underscore'], function (_) {
  ...
});

This works fine in the browser, but causes errors in Node:

Error: Calling node require("use") failed with error: Error: Cannot find module 'use'

I believe this does not apply to the use plugin, but also etc.

Has anyone else encountered this problem?

+3
1

0.3 node. - , .

0

All Articles