当我在控制台中键入$npm build时,bash脚本并没有运行



我想写一个批处理脚本(build.sh(来安装依赖项,同时运行前端和后端

package.json文件

"scripts": {
"dev": "nodemon server.js",
"client": "cd client && npm start",
"start": "concurrently "npm run dev" "npm run client" ",
"build": "chmod +x ./build.sh"
},

build.sh文件

#!/bin/bash
npm run build
npm i aws-sdk body-parser concurrently cors dotenv express joi mongoose multer multer-s3 
cd client
npm i axios bootstrap config jquery node-modules react react-bootstrap react-dom react-scripts redux redux-form redux-thunk web-vitals 
cd ..
npm start

我不确定我错过了什么才能让它正常运行?提前感谢!

当我在命令行(当然是在应用程序的目录中(中键入$ npm build时,我得到的是:

Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview
Specify configs in the ini-formatted file:
/Users/SebastianRusso/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@6.14.5 /usr/local/lib/node_modules/npm
Did you mean this?
rebuild
Sebastians-MacBook-Pro:profile-app-server SebastianRusso$ npm buildd
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview
Specify configs in the ini-formatted file:
/Users/SebastianRusso/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@6.14.5 /usr/local/lib/node_modules/npm
Did you mean this?
rebuild

build不是npm的有效CLI命令。要运行在package.json中定义的build脚本,请执行$ npm run build

"build": "chmod +x ./build.sh"

应该是:

"build": "./build.sh"

chmod +x只是使build.sh文件可执行,它实际上并没有运行它

然后,要从npm运行build命令,您必须像另一个答案所说的那样使用npm run build

最新更新