node.js - 我正在尝试将我的 node.js 应用程序部署到 heroku

标签 node.js heroku nestjs

我正在尝试将我的 node.js 应用程序部署到 Heroku 中,但是当我尝试将我的项目推送到 Heroku 分支时,我得到:

remote: node_modules/@types/jsdom/base.d.ts:192:18 - error TS2411: Property '["Infinity"]' of type 'number' is not assignable to 'number' index type 'Window'.
remote: 
remote: 192         readonly ["Infinity"]: number;
remote:                      ~~~~~~~~~~~~
remote: node_modules/@types/jsdom/base.d.ts:193:18 - error TS2411: Property '["NaN"]' of type 'number' is not assignable to 'number' index type 'Window'.
remote: 
remote: 193         readonly ["NaN"]: number;
remote:                      ~~~~~~~
remote: 
remote:        Found 2 error(s).

Node.Js 版本:v17.0.1 npm 版本:8.1.0

这个项目我是用nest.js框架开发的,其实在本地环境启动的时候没有问题。

最佳答案

潜在的问题是最近更新了传递依赖项,并且该更新与 typescript 不兼容。另外,我猜你的项目没有使用锁定文件,如果是这种情况,那就不太理想了。

对于我的 nestjs 项目,问题在于 jest 的传递依赖。如果您正在使用 jest,请参阅此 github 讨论以跟进并获取更新,如果您不能立即开始使用锁定文件,可能还会获得一些关于如何解决它的提示 https://github.com/facebook/jest/issues/12098 (似乎在底层 repo 中打开了一个 PR,但可能需要一些时间才能获得批准并更新到 npm 的注册表。https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57432)

如果您没有在您的 git 存储库中提交 package-lock.json 文件,您应该添加它。 Heroku 使用 package.json 或 package-lock.json 为您安装依赖项,如果您想要可重现的构建,您绝对应该使用 package-lock.json。如果您在本地有一个 package-lock.json 文件并且当前被 git 忽略,您可以删除 .gitignore 文件中的条目。

有关它如何处理 package-lock.json 的更多信息,请参阅 Heroku 的文档:https://devcenter.heroku.com/articles/nodejs-support#package-installation

Heroku uses the lockfiles, either the package-lock.json or yarn.lock, to install the expected dependency tree, so be sure to check those files into git to ensure the same dependency versions across environments. If you are using npm, Heroku will use npm ci to set up the build environment.

关于node.js - 我正在尝试将我的 node.js 应用程序部署到 heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70164067/

相关文章:

mqtt - 如何在 NestJS 上发布 mqtt?

typescript - NestJS 随处访问 Reponse

javascript - NestJS : transform responses

node.js - 在heroku上部署 Node 应用程序引发与nodemon相关的错误

javascript - 在 winston v3 中 T there <A>($winston Logger Config<T>) => $winston Logger<T> 是什么意思?

django - Heroku 和 Django 连接池

node.js - Heroku Postgres 无法在 Windows 上拉动和推送

node.js - POST 到 AWS EC2 Mongodb 数据库在生产中不起作用

node.js - Azure 应用服务突然提供文件目录概述而不是 Angular 应用

ruby-on-rails - 是什么导致我的 Heroku 应用程序出现这些错误?