简体   繁体   English

找不到模块'.../models/user' nodejs

[英]Cannot find module '…/models/user' nodejs

I just found a cool project that I want to clone and explore, but I getting this weird error.我刚刚找到了一个很酷的项目,我想克隆和探索它,但我收到了这个奇怪的错误。 I tried to read some similar solution here but couldn't find any.我试图在这里阅读一些类似的解决方案,但找不到任何解决方案。

after executing npm start, i getting this error.执行 npm start 后,我​​收到此错误。 在此处输入图片说明

You can clone the project from here.您可以从这里克隆项目。 https://github.com/didinj/mern-stack-authentication https://github.com/didinj/mern-stack-authentication

I have installed as described.我已经按照说明安装了。 在此处输入图片说明

From the Err message:从错误消息:

Error: Cannot find module '../models/user' It simply cannot resolved the path to User.js file.错误:找不到模块 '../models/user' 它根本无法解析 User.js 文件的路径。

In your auth.js and passport.js file rename or change this import line of code在您的 auth.js 和passport.js 文件中重命名或更改此导入代码行

var User = require('../models/user');

to

var User = require('../models/User');

I notice the file name is User.js not user.js我注意到文件名是User.js而不是user.js

First of all you need to execute首先你需要执行

npm install

This will install all of project's dependencies.这将安装所有项目的依赖项。

Your file name is User not user , so please update auth.js and replace你的文件名是User而不是user ,所以请更新auth.js并替换

var User = require("../models/user");

with

var User = require("../models/User");

It is not able to find the module named ../models/user because your file name is User.js not 'user.js' inside Models folder.它无法找到名为../models/user的模块,因为您的文件名是User.js而不是 Models 文件夹中的“user.js”。

you can either change the name of the file from 'User.js' to 'user.js'您可以将文件名从“User.js”更改为“user.js”

or或者

you can change the require('../models/user') to require('../models/User') in your 2 files- auth.js and passport.js您可以将 2 个文件中的require('../models/user')更改为require('../models/User') - auth.js 和passport.js

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

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