无法在Heroku上编译代码,出现错误

时间:2019-08-17 19:50:46

标签: javascript node.js heroku

我无法在heroku上编译代码,因为它在json-stringify-safe上提供了一些错误(我的本地计算机上没有该模块)。我按下heroku,并收到此错误:

2019-08-17T19:35:33.546554+00:00 app[web.1]: ###
2019-08-17T19:35:33.546557+00:00 app[web.1]: ### The "request" library is not installed automatically anymore.
2019-08-17T19:35:33.546558+00:00 app[web.1]: ### But is a dependency of "request-promise".
2019-08-17T19:35:33.546560+00:00 app[web.1]: ### Please install it with:
2019-08-17T19:35:33.546561+00:00 app[web.1]: ### npm install request --save
2019-08-17T19:35:33.546563+00:00 app[web.1]: ###
2019-08-17T19:35:33.546564+00:00 app[web.1]:
2019-08-17T19:35:33.548891+00:00 app[web.1]: /app/node_modules/json-stringify-safe/stringify.js:19
2019-08-17T19:35:33.548908+00:00 app[web.1]: var thisPos = stack.indexOf(this) ~thisPos ? stack.splice(thisPos + 1) : stack.push(this) ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key)
2019-08-17T19:35:33.548910+00:00 app[web.1]: ^
2019-08-17T19:35:33.548911+00:00 app[web.1]:
2019-08-17T19:35:33.548913+00:00 app[web.1]: SyntaxError: Unexpected token ~
2019-08-17T19:35:33.548914+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:723:23)
2019-08-17T19:35:33.548916+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-08-17T19:35:33.548917+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-08-17T19:35:33.548919+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-08-17T19:35:33.548920+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-08-17T19:35:33.548922+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-08-17T19:35:33.548923+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-08-17T19:35:33.548924+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/request/lib/helpers.js:3:25)
2019-08-17T19:35:33.548926+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-08-17T19:35:33.548927+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-08-17T19:35:33.548929+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-08-17T19:35:33.548930+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-08-17T19:35:33.548932+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-08-17T19:35:33.548933+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-08-17T19:35:33.548934+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-08-17T19:35:33.548936+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/request/index.js:19:15)
2019-08-17T19:35:33.548937+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-08-17T19:35:33.548939+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-08-17T19:35:33.548940+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-08-17T19:35:33.548941+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-08-17T19:35:33.548943+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-08-17T19:35:33.548944+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-08-17T19:35:33.605417+00:00 heroku[web.1]: Process exited with status 1

2 个答案:

答案 0 :(得分:0)

问题主要源于“'request'库不再自动安装”。

要解决此问题,您需要先安装请求库

npm i request

然后安装请求承诺库

npm i request-promise

答案 1 :(得分:0)

request-promise自2020年2月起不推荐使用,请使用Superagent之类的另一个库