简体   繁体   English

在 Heroku 上运行时找不到模块“./mergeConfig”

[英]Cannot find module './mergeConfig' when running on Heroku

I have a node application that runs fine when executed on my machine via node my_application.js .我有一个节点应用程序,当通过node my_application.js在我的机器上执行时它运行良好。

However, if push it to heroku and execute it via heroku run node my_application.js or with the scheduler what I get is this error:但是,如果将它推送到 heroku 并通过heroku run node my_application.js或使用调度程序执行它,我得到的是这个错误:

internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module './mergeConfig'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/app/node_modules/axios/lib/core/Axios.js:7:19)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

I'm running node v10.16.0 and npm v6.9.0 both locally and on Heroku, so I really don't know what may be causing this issue, and googling for it didn't help in any way.我在本地和 Heroku 上运行 node v10.16.0 和 npm v6.9.0,所以我真的不知道是什么导致了这个问题,谷歌搜索也没有任何帮助。

Any ideas about this mergeConfig module that seems to be missing from my heroku environment but not from my local environment?我的heroku环境中似乎缺少有关此mergeConfig模块的任何想法,但我的本地环境中却没有?

Edit: this is my package.json:编辑:这是我的 package.json:

{
  "name": "[REDACTED]",
  "version": "1.0.0",
  "description": "[REDACTED]",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.19.0",
    "bluebird": "^3.5.3",
    "body-parser": "^1.18.3",
    "dateformat": "^3.0.3",
    "express": "^4.16.4",
    "form-data": "^2.3.3",
    "http-to-curl": "^1.4.2",
    "jest": "^24.8.0",
    "qs": "^6.6.0",
    "querystring": "^0.2.0",
    "redis": "^2.8.0",
    "simple-oauth2": "^2.2.1"
  }
}

Try to add explicitly the missing module in the dependencies in package.json:尝试在 package.json 的依赖项中明确添加缺少的模块:

 "dependencies": {
       ...
       "merge-config" :"2.0.0"
       ...
}

I think it works on your local environment because you have the module installed globally.我认为它适用于您的本地环境,因为您已全局安装该模块。

I had the same problem.我有同样的问题。 './mergeConfig' is a file inside de axios module. './mergeConfig' 是 de axios 模块中的一个文件。

Path: node_modules/axios/core/mergeConfig.js路径:node_modules/axios/core/mergeConfig.js

For some reason heroku had a problem with this file.出于某种原因,heroku 对这个文件有问题。 I solved it by replacing axios with request.我通过用请求替换 axios 来解决它。

This fixed the problem for me NODE_OPTIONS=--max_old_space_size=4096这为我解决了问题NODE_OPTIONS=--max_old_space_size=4096

src: https://github.com/axios/axios/issues/1767#issuecomment-416924946源代码: https : //github.com/axios/axios/issues/1767#issuecomment-416924946

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

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