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

I am trying to deploy my node.js application into heroku

我正在尝试将我的 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框架开发的,其实我在本地环境启动的时候没有问题

使用 tsconfig.json 中的选项 skipLibCheck: true 可能是一个临时解决方案。

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

对于我的 nestjs 项目,问题在于 jest 的传递依赖性。如果您使用的是 jest,请参阅此 github 讨论以跟进并获取更新,如果您不能立即开始使用锁定文件,可能还会获得一些关于如何解决它的提示 https://github.com/facebook/jest/issues/12098 (There seems to be a PR opened up in the underlying repo, but it might take some time to get approved and updated to npm's registry. 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 文件中的条目。

查看 Heroku 的文档以了解有关它如何处理包的更多信息-lock.json: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.