0

我试图让最简单的 node.js 脚本工作。这是javascript文件:

服务器.js

require("express");

我使用常规节点命令启动脚本:

$ node server.js

但我收到一个错误:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
    at Function.<anonymous> (module.js:378:11)
    at Object.<anonymous> (/home/shawn/.node_libraries/express@2.5.9/index.js:4:21)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:32)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/shawn/Documents/Projets/passingData/server.js:3:15)
    at Module._compile (module.js:441:26)

这是怎么回事?

更新

有趣的是,使用npm install express输出类似的结果:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
    at Function.<anonymous> (module.js:378:11)
    at Object.<anonymous> (/home/shawn/.node_libraries/mkdirp@0.3.0/index.js:4:21)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:32)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/usr/lib/nodejs/fstream/lib/dir-reader.js:11:13)
    at Module._compile (module.js:441:26)
4

1 回答 1

1

您需要像这样全局安装它(如果您不将其构建为包)

npm install express -g

或者如果你有它,package.json你必须进行本地安装npm install -l,它会正常工作。

于 2012-06-10T21:14:10.140 回答