node.js - 当我尝试在 Heroku 中构建 NodeJS 应用程序时,Typescript 上出现错误 TS2307
问题描述
当我执行命令git push heroku master
时,在构建步骤中返回错误。
但是,在本地环境中,使用相同版本的 NodeJS 和 NPM 不会发生错误。该系统也 100% 被自动化测试覆盖,并且没有测试返回错误。
如何复制此问题:
git clone https://github.com/felinto-dev/clean-node-api-ts
cd clean-node-api-ts
git init -y
git push heroku master
错误日志:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 12.x
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 12.x...
remote: Downloading and installing node 12.18.2...
remote: Using default npm version: 6.14.5
remote:
remote: -----> Restoring cache
remote: - node_modules
remote:
remote: -----> Installing dependencies
remote: Installing node modules (package.json)
remote: added 1 package from 1 contributor, updated 1 package and audited 1020 packages in 8.612s
remote:
remote: 52 packages are looking for funding
remote: run `npm fund` for details
remote:
remote: found 0 vulnerabilities
remote:
remote:
remote: -----> Build
remote: Running build
remote:
remote: > clean-node-api@1.1.0 build /tmp/build_4fc3d9921e6aaa1c4e6d21786f8596fe
remote: > rm -rf dist && tsc
remote:
remote: src/data/protocols/db/account/add-account-repository.ts(2,30): error TS2307: Cannot find module '../../../../domain/models/account' or its corresponding type declarations.
remote: src/data/protocols/db/account/load-account-by-email-repository.ts(1,30): error TS2307: Cannot find module '../../../../domain/models/account' or its corresponding type declarations.
remote: src/data/usecases/add-account/db-add-account-protocols.ts(2,15): error TS2307: Cannot find module '../../../domain/models/account' or its corresponding type declarations.
remote: src/data/usecases/add-account/db-add-account.spec.ts(2,35): error TS2305: Module '"./db-add-account-protocols"' has no exported member 'AccountModel'.
remote: src/data/usecases/add-account/db-add-account.ts(1,39): error TS2305: Module '"./db-add-account-protocols"' has no exported member 'AccountModel'.
remote: src/data/usecases/authentication/db-authentication-protocols.ts(1,15): error TS2307: Cannot find module '../../../domain/models/account' or its corresponding type declarations.
remote: src/data/usecases/authentication/db-authentication.spec.ts(3,3): error TS2305: Module '"./db-authentication-protocols"' has no exported
member 'AccountModel'.
remote: src/domain/usecases/add-account.ts(1,30): error TS2307: Cannot find module '../models/account' or its corresponding type declarations.
remote: src/infra/db/mongodb/account/account-mongo-repository.ts(3,30): error TS2307: Cannot find module '../../../../domain/models/account' or
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: Some possible problems:
remote:
remote: - A module may be missing from 'dependencies' in package.json
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to felinto-clean-node-api-ts.
remote:
To https://git.heroku.com/felinto-clean-node-api-ts.git
! [remote rejected] master -> master (pre-receive hook declined)
! [remote rejected] 1.0.0 -> 1.0.0 (pre-receive hook declined)
! [remote rejected] 1.1.0 -> 1.1.0 (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/felinto-clean-node-api-ts.git'
解决方案
在你的 package.json 文件中试试这个
"scripts": { "build": "tsc", "heroku-postbuild": "npm run build", "start": "node build/app.js" },
推荐阅读
- firebase - 如何从云 Firestore 中的存储中引用图像?反应
- constants - 如何在 Tcl 中创建常量?
- java - 如何在 Recycler 视图上使用 onFling 手势检测器监听器
- python - 如何通过按“r”按钮重新启动我的程序?
- entity-framework - 使用 LINQ 搜索逗号分隔的字符串
- python - 将关系 1:N 数据的 pandas 数据帧转换为嵌套 JSON
- android - @composable 调用只能在 @composable 函数的上下文中发生
- python - OneHotEncoding 分类数据
- powershell - 如何使用PowerShell批量重新格式化文件的日期
- python - 在读取文件期间在python中将文件名作为变量传递