首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node.js -“找不到模块'module.js‘”

Node.js -“找不到模块'module.js‘”
EN

Stack Overflow用户
提问于 2016-10-10 03:39:34
回答 4查看 18.3K关注 0票数 2

我正在使用Heroku,我得到了这个错误..。

代码语言:javascript
复制
2016-10-10T03:34:11.188366+00:00 app[web.1]: Error: Cannot find module 'module1.js'
2016-10-10T03:34:11.188369+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:339:15)
2016-10-10T03:34:11.188370+00:00 app[web.1]:     at Function.Module._load (module.js:290:25)
2016-10-10T03:34:11.188371+00:00 app[web.1]:     at Module.require (module.js:367:17)
2016-10-10T03:34:11.188371+00:00 app[web.1]:     at require (internal/module.js:20:19)
2016-10-10T03:34:11.188372+00:00 app[web.1]:     at Object.<anonymous> (/app/server.js:42:15)
2016-10-10T03:34:11.188373+00:00 app[web.1]:     at Module._compile (module.js:413:34)
2016-10-10T03:34:11.188374+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:422:10)
2016-10-10T03:34:11.188374+00:00 app[web.1]:     at Module.load (module.js:357:32)
2016-10-10T03:34:11.188375+00:00 app[web.1]:     at Function.Module._load (module.js:314:12)
2016-10-10T03:34:11.188375+00:00 app[web.1]:     at Function.Module.runMain (module.js:447:10)

app.js

代码语言:javascript
复制
/**CUSTOM_MODULES**/

var module1 = require('module1.js');

/**MODULES_END**/

module1.js

代码语言:javascript
复制
function module1(){
    //My code
}

module.exports = module1;

module1.js与我的app.js位于同一个目录中。

我试过无数的东西,但似乎什么都没有用。

我试过:

代码语言:javascript
复制
 var module1 = require('module1.js');
 var module1 = require('./module1.js');
 var module1 = require('../module1.js');
 var module1 = require('module1');

package.json : app.js

代码语言:javascript
复制
{
  "name": "nano-server",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "dependencies": {
    "express": "^4.14.0",
    "mysql": "^2.11.1",
    "socket.io": "^1.4.8",  
    "module1": "0.0.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC"
}

package.json : module1

代码语言:javascript
复制
 {
  "name": "module1",
  "version": "0.0.0",
  "description": "get something",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": {
    "name": "sergey"
  },
  "license": "BSD-2-Clause",
  "readme": "ERROR: No README data found!",
  "_id": "module1@0.0.0",
  "dist": {
    "shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
    "tarball": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
  },
  "_from": "module1@latest",
  "_npmVersion": "1.3.11",
  "_npmUser": {
    "name": "sergey-user",
    "email": "aaa@mail.ru"
  },
  "maintainers": [
    {
      "name": "sergey-user",
      "email": "aaa@mail.ru"
    }
  ],
  "directories": {},
  "_shasum": "dc9b96f8a43b596bf735da4d2004ba410429bde0",
  "_resolved": "https://registry.npmjs.org/module1/-/module1-0.0.0.tgz"
}

目录

代码语言:javascript
复制
_server
    .git
    node_modules
        .bin
        express
        module1
            index.js
            package.json
        mysql
        node-mysql
        node-uuid
        socket.io
    package.json
    server.js
EN

回答 4

Stack Overflow用户

发布于 2016-10-10 03:44:21

试试var module1 =需要量(‘./module1 1’);

票数 7
EN

Stack Overflow用户

发布于 2016-10-10 03:46:58

安装npm -g,然后再试一次。

票数 1
EN

Stack Overflow用户

发布于 2016-10-10 03:56:00

将模块作为依赖项添加到应用程序中将解决此问题。要实现这一点,请尝试下面的命令。

npm install module1 --save

希望这能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39950984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档