如何在Heroku安装后编译Typescript? [英] How do I compile Typescript at Heroku postinstall?
问题描述
我不想上传预编译的dist目录,而是要在服务器端编译src.
Instead of uploading the precompiled dist directory, I want to compile src at server side instead.
这是我在package.json中的脚本:
Here are my scripts inside package.json:
"scripts": {
"test": "echo \"No test specified\" && exit 0",
"start": "node dist/app.js",
"postinstall": "tsc"
}
这里是依赖项:
"dependencies": {
"@types/express": "^4.11.1",
"@types/pg": "^7.4.4",
"@types/socket.io": "^1.4.31",
"body-parser": "^1.18.2",
"express": "^4.16.2",
"pg": "^7.4.1",
"socket.io": "^2.0.4",
"tslint": "^5.9.1",
"typescript": "^2.7.2"
}
由于"npm install将在安装过程中将node_modules/.bin文件夹添加到PATH环境变量中",Heroku应该能够直接调用它.
Since 'npm install will add the node_modules/.bin folder to the PATH environment variable during installation', Heroku should be able to call it directly.
但这是我得到的错误:
Building dependencies
Installing node modules (package.json + package-lock)
> bilgi-yarismasi@1.0.0 postinstall /tmp/build_afa42c7943d4b71d2b48a016ae3b9e50
> tsc
sh: 1: tsc: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! bilgi-yarismasi@1.0.0 postinstall: `tsc`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the bilgi-yarismasi@1.0.0 postinstall 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.LTxbD/_logs/2018-02-25T10_36_06_374Z-debug.log
-----> Build failed
推荐答案
您需要从npm脚本中调用 tsc
.否则,Heroku会尝试查找名为 tsc
的全局依赖项.
You need to call tsc
from an npm script. Otherwise Heroku tries to find a global dependency named tsc
.
在您的 package.json
中创建一个新的npm脚本:
Create a new npm script in your package.json
:
"tsc": "tsc"
现在将"postinstall":"tsc"
替换为:
"postinstall": "npm run tsc"
这篇关于如何在Heroku安装后编译Typescript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!