Node.js 将TypeScript解压缩到Heroku时出现声明错误

Node.js 将TypeScript解压缩到Heroku时出现声明错误,node.js,typescript,heroku,npm,deployment,Node.js,Typescript,Heroku,Npm,Deployment,我正在尝试将我的TypeScript API部署到Heroku。我有一个heroku预构建脚本运行npmi&&npmi-g typescript&&npm run build,一个构建脚本运行tsc 因此,我安装了一些带有相应类型标记的新软件包,并从Heroku那里得到了错误: -----> Node.js app detected -----> Creating runtime environment NPM_CONFIG_LOGLEV

我正在尝试将我的TypeScript API部署到Heroku。我有一个heroku预构建脚本运行
npmi&&npmi-g typescript&&npm run build
,一个构建脚本运行
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\u modules
文件夹。但我关闭了它,并且每个包都有声明错误

GitHub回购


如何修复此问题?

heroku prebuild
在heroku安装依赖项之前运行,这就是您必须自行安装的原因;为什么不让Heroku安装,然后运行
build
?这样package.json中的build命令就会自动运行?是的,非常感谢!你想发布一个答案,这样我可以标记为正确吗?这不是答案,这不能解释为什么当前安装程序在运行安装程序时无法工作。