node.js module.js:340错误:找不到模块 [英] nodejs module.js:340 error: cannot find module

查看:116
本文介绍了node.js module.js:340错误:找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C:\ Program Files(x86)\ nodejs中安装了nodejs

I installed nodejs in C:\Program Files (x86)\nodejs

然后我创建了一个.js文件并将其保存在桌面中,只是为了在控制台中输出"hello world":

then I created a .js file and saved it in my desktop just to output 'hello world' in the console:

console.log('hello world');

当我尝试从命令提示符下运行文件时:

When I tried to run the file from the command prompt:

C:\Users\Laura>cd desktop
C:\Users\Laura\Desktop>node nodeTest.js

我得到:

module.js:340
throw err;
      ^
Error: Cannot find module 'C:\Users\Laura\Desktop\testNode.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

我阅读了许多其他相关问题,其中一些建议运行安装程序,所以我做到了.

I read many other related questions, and some of them recommend to run the install, and so I did.

C:\Users\Laura>npm install -g express

但是没有运气,仍然收到相同的错误消息.

But no luck, still getting the same error message.

推荐答案

EDIT :此答案已过时.使用Yarn和NPM 5的锁定文件之类的东西,现在可以更轻松地确保您在Heroku等平台上的依赖关系正确

EDIT: This answer is outdated. With things like Yarn and NPM 5's lockfiles it is now easier to ensure you're dependencies are correct on platforms like Heroku

我有一个类似的问题,与以某种方式在本地修改了node_modules有关,但是更改未反映在Heroku上,导致我的应用程序崩溃.如果这是您的问题,则相对容易解决:

I had a similar issue related to node_modules being modified somehow locally but the change was not reflect on Heroku, causing my app to crash. It's relatively easy fix if this is your issue:

# Remove node_modules
rm -fr node_modules

# Reinstall packages
npm i

# Commit changes
git add node_modules
git commit -m 'Fix node_modules dependencies.'
git push heroku master

希望对遇到类似问题的人有所帮助.

Hope that helps for others with a similar issue.

这篇关于node.js module.js:340错误:找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆