开发者

Error: require.paths is removed. when running node.js & socket.io

开发者 https://www.devze.com 2023-04-07 11:43 出处:网络
(javascript) Iv got an error in running a socket.io example from github https://github.com/LearnBoost/socket.io.git

(javascript) Iv got an error in running a socket.io example from github https://github.com/LearnBoost/socket.io.git

when i run -> node app.js it says. Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.

can so开发者_JS百科meone tell me whats wrong? this error always comes out in every socket.io examples I've tried.


I hit this issue while working with a cloud foundry sample. The offending line they told you to include was:

require.paths.unshift('./node_modules')

It's apparently a way of telling node what path to search in for modules you require, in those cases where you don't provide an explicit path. I read somewhere that's when the string you pass in does not start with a dot or a slash.

As far as I can tell it's something that is required to make Node 0.4 applications search in the node_modules directory. But in Node 0.6 you're supposed to sort this out with settings in your environment and path instead (though it seemed to work by default for me on an 0.6 install).

I was having trouble because the cloud deployment was on Node 0.4 and my local development setup was on Node 0.6. Having the line crashed me locally, but leaving it out crashed on the cloud. My solution was to delete it and instruct the cloud to use 0.6 with:

vmc push <appname> --runtime=node06

Everything seemed to work after that. Even better: I found that you can edit your manifest.yml file to tell it do this automatically during the push with no command line switch needed:

---
applications:
  .:
    name: myapp
    runtime: node06  # added this line
    framework:
      name: node
      info:
        mem: 64M
        description: Node.js Application
        exec: n

(etc.)

Incidentally...if it had been necessary to dual support older versions of node that needed require.paths as well, one could maybe run the line conditionally based on testing process.version:

http://nodejs.org/docs/v0.4.9/api/process.html#process.version


May be you can try https://github.com/cloudhead/less.js/issues/320 This is something similar to your problem.


try something like this:

var dust = require('dustjs-helpers');

var compiled = dust.compile("Hello {name}!", "intro");

dust.loadSource(compiled);

dust.render("intro", {
    name: "Márcio"
}, function(err, out) {
    console.log(out);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号