这是我的package.json脚本的一部分。
"scripts": {
"deploy": "aws s3 sync ./out s3://[my bucket name] --acl public-read --delete"
}我使用alias设置.bashrc,如下所示
alias aws="winpty C:/Program\ Files/Amazon/AWSCLIV2/aws.exe"aws --version工程
$ aws --version
aws-cli/2.8.2 Python/3.9.11 Windows/10 exe/AMD64 prompt/offs3 sync命令也可以工作(忽略权限问题)。我稍后再解决)。
$ aws s3 sync ./out s3://[my bucket name] --acl public-read --delete
fatal error: An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records.但当我试着用剧本..。轰隆!发生错误!
$ npm run deploy
> myProject@0.1.0 deploy
> aws s3 sync ./out s3://[my bucket name] --acl public-read --delete
'aws' is not recognized as an internal or external command, operable program or batch file.我怎样才能克服这个障碍?
发布于 2022-10-13 02:35:26
当你有..。
"scripts": {
"deploy": "aws some-params"
}...and你做的..。
npm run deploy.国家预防机制将如何运作脚本(即aws some-params)依赖于平台。来自医生们
默认情况下,在类似Unix的系统上,它是
/bin/sh命令,在Windows上是cmd.exe命令./bin/sh引用的实际shell也取决于系统。您可以使用script-shell配置自定义外壳。
所以当你得到错误时:
'aws' is not recognized as an internal or external command, operable program or batch file.
如果你在谷歌上搜索它,你会注意到它正是cmd.exe抛出的错误的格式。
现在,您可以使用.bashrc将aws定义为alias。它很好,但是只有当您的shell是git bash时才能工作,也就是说,cmd.exe将不知道这个alias,因此会抛出一个错误--就像它所做的那样。
修复
现在,你有一些可能性:
您可以编辑windows注册表以将类似于.bashrc的内容添加到cmd.exe (参见如何完成该这里)。
或者,您可以为您的NPM设置script-shell。或者你可以package.json,例如,
"script-shell": "C:\\Program Files\\git\\bin\\bash.exe",
"scripts": {
"deploy": "aws some-params"
}或者你可以在全球范围内设置它:
npm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"当然,所有这些假设您的git在C:\Program Files\git\bin\bash.exe。
https://stackoverflow.com/questions/74038546
复制相似问题