In order to share AMD modules between the browser and node, I'm using 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 has generally been working ok, as long as the shared module does not involve any dependencies that don't work on the server.
I would like to introduce use.js, however, to avoid manually wrapping non-AMD compatible libs like underscore. To do so, I have to prefix listed dependencies with use!
(to trigger the use plugin in RequireJS).
client/resource.js:
define(['use!underscore'], function (_) {
...
});
This works well in the browser, but causes errors in Node:
Error: Calling node's require("use") failed with error: Error: Cannot find module 'use'
I believe this is not specific to the use plugin, but also text etc.
Has anyone else encountered this problem?