简体   繁体   English

在本地运行Node.js应用程序时指向不存在的文件时出错

[英]Error pointing to non-existent file when running Node.js app locally

I was just sent the files for a Node.js app (which is working without issues online) and I'm trying to set it up on my Windows machine. 我刚收到一个Node.js应用程序的文件(该文件可以正常运行,没有任何在线问题),我正在尝试在Windows计算机上进行设置。

I have Node server running, but I'm stuck trying to actually load the app. 我正在运行节点服务器,但是在尝试实际加载应用程序时遇到了困难。 I can navigate to the directory with the Node command prompt, and there's an app.js (plus folders like config , components etc) in there which I've been trying to run, but I am getting the following error: 我可以使用Node命令提示符导航到该目录,并且在那里一直尝试运行一个app.js (以及configcomponents等文件夹),但是出现以下错误:

D:\my-directory\game-master>node app.js
module.js:327
    throw err;
    ^

Error: Cannot find module 'config'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (D:\posao\aktivni projekti\smart rebellion\game-master
\app.js:7:10)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

The thing is, there is no file titled module.js in the directory. 问题是,目录中没有名为module.js的文件。 I presume it's a built in Node.js file, but then how do I troubleshoot this? 我认为它是内置的Node.js文件,但是该如何解决呢?

My best reading of the error is that there should be a config.js file somewhere, but that doesn't make sense because these same exact files work with no hickups on a remote server. 我对错误的最佳理解是,应该在某个位置放置config.js文件,但这没有任何意义,因为这些相同的文件在远程服务器上不会出现异常。

If you want to require('./config') , where config is a directory, the file ./config/index.js should exist. 如果您需要require('./config') ,其中config是目录,则文件./config/index.js应该存在。

You can't require('config') however, because node.js will try to find it in node_modules . 但是,您require('config') ,因为node.js会尝试在node_modules找到它。

Check out node.js modules documentation where the require algorithm is well explained. 查看node.js模块文档 ,其中对require算法进行了很好的说明。

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

相关问题 将node.js应用程序指向我的IP地址并在本地运行 - pointing node.js app to my ip address and running locally 节点模块导出,访问不存在的属性错误,Jasmine - node module exports, Accessing non-existent property error, Jasmine 在本地运行Azure Node.js应用-连接到同一数据库 - Running Azure Node.js app locally - connecting to same database 在Heroku错误上运行Node.js应用 - Running Node.js App on Heroku Error 在运行 Node.js 运行时(甚至自定义运行时)的 gcloud App Engine 中安装 numpy。 在本地运行良好但在部署时出错 - Installing numpy in gcloud App Engine running Node.js runtime (or even custom runtime). Running fine locally but getting errors when deployed Node.js 应用程序在本地运行,但在部署到 heroku 时出现应用程序错误 - Node.js app works locally but when deploy to heroku I get application error Heroku Node.js 应用程序在本地运行,但在部署时不运行 - Heroku Node.js App Works Locally but not when deployed node.js 应用程序在本地运行但在部署到 heroku 时崩溃 - node.js app works locally but crashes when deployed on heroku Node.js在本地返回JS文件 - Node.js return a JS file locally firebase 部署节点“警告:访问不存在的属性” - firebase deploy Node “Warning: Accessing non-existent property”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM