我正在尝试将TypeScript API部署到Heroku。我有一个运行npm i && npm i -g typescript && npm run build
的heroku-prebuild脚本和一个运行tsc
的构建脚本。
所以我安装了一些带有相应类型标称的新软件包,并从Heroku中得到了错误:
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
-----> Installing binaries
engines.node (package.json): 12.x
engines.npm (package.json): unspecified (use default)
Resolving node version 12.x...
Downloading and installing node 12.18.4...
Using default npm version: 6.14.6
-----> Restoring cache
- node_modules
-----> Prebuild
Running heroku-prebuild
> swooosh-api@1.0.0 heroku-prebuild /tmp/build_fc3ad6d3
> npm i && npm i -g typescript && npm run build
audited 237 packages in 2.088s
12 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
/tmp/build_fc3ad6d3/.heroku/node/bin/tsc -> /tmp/build_fc3ad6d3/.heroku/node/lib/node_modules/typescript/bin/tsc
/tmp/build_fc3ad6d3/.heroku/node/bin/tsserver -> /tmp/build_fc3ad6d3/.heroku/node/lib/node_modules/typescript/bin/tsserver
+ typescript@4.0.3
added 1 package from 1 contributor in 1.843s
> swooosh-api@1.0.0 build /tmp/build_fc3ad6d3
> tsc
api/utils/config.ts(1,23): error TS7016: Could not find a declaration file for module 'express-rate-limit'. '/tmp/build_fc3ad6d3/node_modules/express-rate-limit/lib/express-rate-limit.js' implicitly has an 'any' type.
Try `npm install @types/express-rate-limit` if it exists or add a new declaration (.d.ts) file containing `declare module 'express-rate-limit';`
api/utils/config.ts(2,22): error TS7016: Could not find a declaration file for module 'express-slow-down'. '/tmp/build_fc3ad6d3/node_modules/express-slow-down/lib/express-slow-down.js' implicitly has an 'any' type.
Try `npm install @types/express-slow-down` if it exists or add a new declaration (.d.ts) file containing `declare module 'express-slow-down';`
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! swooosh-api@1.0.0 build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the swooosh-api@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.saClh/_logs/2020-10-04T13_30_28_587Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! swooosh-api@1.0.0 heroku-prebuild: `npm i && npm i -g typescript && npm run build`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the swooosh-api@1.0.0 heroku-prebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/npmcache.saClh/_logs/2020-10-04T13_30_28_605Z-debug.log
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
If you're stuck, please submit a ticket so we can help:
https://help.heroku.com/
Love,
Heroku
! Push rejected, failed to compile Node.js app.
! Push failed
我认为问题是Heroku缓存了node_modules
文件夹。但是我关闭了该功能,每个软件包都有声明错误...
GitHub存储库here
我该如何解决?