首页 > 解决方案 > 当我在控制台中键入 $ npm build 时,bash 脚本没有运行

问题描述

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

包.json 文件

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

构建.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

标签: node.jsbashnpmpackage.json

解决方案


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


推荐阅读