How to run rm command on windows 10?

2020-06-17 15:21发布

"build": "rm -rf ./build && mkdir ./build && ./node_modules/.bin/babel -d ./build ./src"

This is the command in package.json and it gives me an error saying:

rm is not recognized as internal or external command.
Invalid switch /build

5条回答
在下西门庆
2楼-- · 2020-06-17 15:26

In order to run bash commands on Windows you need to install Bash complied for Windows. Install Cygwin and add bin directory to you PATH variable.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-06-17 15:31

That script was written for the UNIX shell, which does not work on windows. The correct way to do this in a cross-platform way is to use rimraf & mkdirp.

Also, the ./node_modules/.bin/babel portion could be shortened to simply babel (./node_modules/.bin/babel doesn't work on windows IIRC).

Properly written, the script should be:

"build": "rimraf ./build && mkdirp ./build && babel -d ./build ./src"

For this script to work, you will have to install rimraf and mkdirp. You can do this by running:

npm install --save-dev rimraf mkdirp

The --save-dev flag will add rimraf and mkdirp to your package.json's devDependencies section so that they will automatically be installed with future npm installs.

查看更多
狗以群分
4楼-- · 2020-06-17 15:40

Not to Bash, but in Windows you can use the built-in remove directory (rd) command:

RD /S /Q "folder-name"
查看更多
Deceive 欺骗
5楼-- · 2020-06-17 15:42

Windows 10 does not provide a UNIX shell by default. You'll need the appropriate UNIX utilities (such as rm) and a shell that supports the syntax you specified.

You have a few options:

  • Use the Windows 10 Bash Shell - Recent versions of Windows 10 now provide beta support for running Ubuntu within Windows without requiring a virtual machine.

  • Use Cygwin for development - Cygwin provides a shell of your choice and plenty of UNIX / Linux utilities.

  • Run a Virtual Machine with a Linux Guest - There are many options for running a VM on Windows. You can use Hyper-V, VirtualBox, or VMware Player. For a guest operating system, Ubuntu is a popular choice, but Fedora and Debian are also common alternatives.

查看更多
女痞
6楼-- · 2020-06-17 15:43

Use rd /s /q "folder name" instead of rm -rf "folder name"

查看更多
登录 后发表回答