【发布时间】:2014-04-17 03:55:10
【问题描述】:
好的,我已经阅读了数十个类似的问题,但没有一个能够解决我的问题 - 主要是因为我认为我的问题有点深。
我有几个模块在我的服务器(Nodejitsu)上运行良好,我认为我安装的方式相同:npm install express/connect/mongojs 等...
在我的 server.js 中:
var express = require('express');
var team = require('./team');
var users = require('./users');
var scheduler = require('node-schedule');
现在我正在尝试让 node-schedule 模块工作,所以我通过 npm 安装 而在我的 server.js 文件的目录中该模块确实进入了 node_modules 文件夹但是当我部署我的应用程序时我明白了:
error: module.js:340
error: throw err;
error: ^
error: Error: Cannot find module 'node-schedule'
error: at Function.Module._resolveFilename (module.js:338:15)
error: at Function.Module._load (module.js:280:25)
error: at Module.require (module.js:364:17)
error: at require (module.js:380:17)
error: at Object.<anonymous> (/opt/run/snapshot/package/server.js:5:1)
error: at Module._compile (module.js:456:26)
error: at Object.Module._extensions..js (module.js:474:10)
error: at Module.load (module.js:356:32)
error: at Function.Module._load (module.js:312:12)
error: at Function.Module.runMain (module.js:497:10)
我认为我的问题可能与我的 package.json 文件有关,该文件几乎是空的:
{
"name": "wePlay",
"subdomain": "wePlay",
"scripts": {
"start": "node server.js"
},
"version": "0.0.0-203",
"engines": {
"node": "0.10.x"
}
}
现在我的 node_modules 文件夹中有我提到的几个模块(express,mongojs ..),并且在我部署时它们都可以正常工作,即使我的 package.json 文件中没有提到它们 - 但现在这个新模块,没有... 我已经尝试(基于过去的线程)使用 -g 安装它,但仍然没有,我也尝试过链接它,没有...
我发现有问题,因为当我尝试部署我的应用程序时,我在应用程序部署时看到了这个问题:
connect@2.7.3 node_modules/connect
├── fresh@0.1.0
├── pause@0.0.1
├── cookie-signature@0.0.1
├── bytes@0.2.0
├── buffer-crc32@0.1.1
├── cookie@0.0.5
├── debug@0.7.2
├── send@0.1.0 (range-parser@0.0.4, mime@1.2.6)
├── formidable@1.0.11
└── qs@0.5.1
express@3.2.2 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── range-parser@0.0.4
├── cookie-signature@1.0.1
├── qs@0.6.3
├── buffer-crc32@0.2.1
├── cookie@0.0.5
├── debug@0.7.2
├── commander@0.6.1
├── mkdirp@0.3.4
├── send@0.1.0 (mime@1.2.6)
└── connect@2.7.8 (pause@0.0.1, bytes@0.2.0, formidable@1.0.13)
nodemailer@0.4.4 node_modules/nodemailer
├── simplesmtp@0.3.1 (xoauth2@0.1.8, rai@0.1.7)
└── mailcomposer@0.1.33 (mime@1.2.9, mimelib@0.2.12)
mongojs@0.7.5 node_modules/mongojs
├── thunky@0.1.0
├── readable-stream@1.0.2
└── mongodb@1.3.6 (kerberos@0.0.2, bson@0.1.8)
显然节点调度不存在。 我似乎无法理解 a)当我的 server.js package.json 为空时,我如何让原始模块工作...... b)当它坐在那里时,怎么可能找不到它,旁边是表达连接和mongojs......
【问题讨论】:
-
节点可能由于权限/所有权而无法读取模块的目录。在您的开发环境中,通常使用
npm install [module] --save将依赖项添加到您的 package.json 中(或者您可以手动添加它)。在此之后,npm install应该安装所有依赖项。 -
感谢您的回答 - 仍然找不到该模块。并且执行 npm install --save 实际上并没有向我的 package.json 添加任何内容。我在 package.json 中手动添加了依赖项,仍然没有
.... "main": "server.js", "dependencies": { "mongojs": "0.7.5", "express": "3.2.2", "node-schedule": "0.1.13" } -
还有其他建议吗?我在这里迷路了..
标签: json node.js package node-modules nodejitsu