简体   繁体   English

找不到模块:在我的带有节点的应用中

[英]Cannot find module: in my app with node

I have problem with my app, the files' tree is: 我的应用程序出现问题,文件树为:

myApp
 controllers
  cars.js
 models
  car.js
 app.js
 package.json

in my code I call my model and mi controller of the next way... 在我的代码中,我以另一种方式调用我的模型和mi控制器...

var express         = require('express');
var bodyParser      = require('body-parser');
var mongoose        = require('mongoose');
var methodOverride  = require("method-override");
var app             = express();
...

**var models = require('./models/car')(app, mongoose);**
**var CarCtrl = require('./controllers/cars');**

but, not working it.. I have the next error: 但是,不起作用..我有下一个错误:

Error: Cannot find module 'controllers/cars' 错误:找不到模块“控制器/汽车”

Error: Cannot find module 'models/car' 错误:找不到模块“模型/汽车”

anything idea? 有什么想法吗? thank you. 谢谢。

Try going to the root first. 尝试先扎根。 require('../myApp/controllers/cars'); require('../ myApp / controllers / cars'); If this didn't work, try console logging the path. 如果这不起作用,请尝试通过控制台记录路径。 Hope this works 希望这行得通

Check both car and cars.js. 检查car和cars.js。 If you require app.js in any of them, you created a chain dependency, which Node.js throws this exact error, that you can't find a module. 如果其中任何一个都需要app.js,则创建一个链依赖关系,Node.js会抛出此确切错误,即找不到模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM