我有一個打字稿檔案,我使用以下命令在本地執行ts-node:
"scripts": {
"commands": "ts-node --files deploy-commands.ts",
},
當我使用 Heroku cli 在 Heroku 部署的應用程式上運行命令時:
heroku run npm run commands
我收到打字稿錯誤:
ts-node --files deploy-commands.ts
/app/node_modules/ts-node/src/index.ts:820
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ? Unable to compile TypeScript:
src/commands/picks.ts:3:26 - error TS7016: Could not find a declaration file for module 'luxon'. '/app/node_modules/luxon/build/node/luxon.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/luxon` if it exists or add a new declaration (.d.ts) file containing `declare module 'luxon';`
3 import { Settings } from 'luxon'
~~~~~~~
at createTSError (/app/node_modules/ts-node/src/index.ts:820:12)
我的 package.json 包含 devDependencies 中的型別(我知道 Heroku 將這些型別剔除)
"devDependencies": {
"@types/luxon": "^2.3.1",
},
所以我添加了 types/index.d.ts :
declare module 'luxon'
但仍然得到錯誤。
uj5u.com熱心網友回復:
直接的問題是它@types/luxon被宣告為開發依賴項,但HerokudevDependencies在默認情況下構建您的應用程式 slug 后會剝離。它們在運行時不可用。
您可以禁用 dev 依賴項修剪或將該依賴項移動到您dependencies的 .
相反,在您的腳本中將其編譯為 JavaScript,build然后運行 ??JavaScript,例如使用類似:
"scripts": {
"build": "tsc",
"commands": "node deploy-commands.js",
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/459869.html
上一篇:對studentType::studentType()的未定義參考
下一篇:Heroku無法獲取/
