简体   繁体   English

在Babel上运行npm运行脚本错误

[英]npm run script error on Babel

I intend to transform JSX during build time instead of during run time. 我打算在构建时而不是在运行时转换JSX。 First, I installed 2 babel tools using the following commands: 首先,我使用以下命令安装了2个babel工具:

$npm install --save-dev babel-cli babel-preset-react
$node_modules/.bin/babel src --presets react --out-dir static

Then in package.json, I added the following under the scripts section. 然后在package.json中,在脚本部分下添加了以下内容。

...
"scripts": {
    "compile": "babel src -presets react -out-dir static",
    "watch": "babel src -presets react -out-dir static -watch",
    "test": "echo \"Error: no test specified\" && exit 1"
},
...

My folder directory is as follows: 我的文件夹目录如下:

Mern\node_modules
Mern\src\app.jsx
Mern\static\app.js
Mern\static\index.html
Mern\package.json
Mern\server.js

When I ran the command: npm run compile, there were a series of errors. 当我运行命令:npm run compile时,出现了一系列错误。

> pro_mern_stack@1.0.0 compile         /Users/comp/Documents/mern
> babel src -presets react -out-dir static

-d doesn't exist. -i doesn't exist. -r doesn't exist

npm ERR! Darwin 16.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "compile"
npm ERR! node v7.10.0
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! pro_mern_stack@1.0.0 compile: `babel src -presets react -out- dir static`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the pro_mern_stack@1.0.0 compile script 'babel src -presets react -out-dir static'.
npm ERR! Make sure you have the latest version of node.js and npm installed.

npm ERR! npm ERR! If you do, this is most likely a problem with the mern package, npm ERR! 如果这样做,这很可能是npm ERR软件包的问题! not with npm itself. 不与npm本身。

I would like to seek advice on what is missing here or is it something with the installation/configuration or folder structure ? 我想就此处缺少的内容或安装/配置或文件夹结构的内容寻求建议。

You missing some '-' in your npm script, must be something like this: 您在npm脚本中缺少一些“-”,必须是这样的:

"scripts": {
"compile": "babel src --presets react --out-dir static",
"watch": "babel src --presets react --out-dir static --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},

When you use '-' - its a short version of option, it takes only 1 char per option, and when you write like -dir, for command its look like: -d -i -r, but '--' takes full name of option. 当您使用'-'-选项的简短版本时,每个选项仅占用1个字符,并且当您像-dir那样编写命令时,其外观如下:-d -i -r,但是'-'需要完整选项名称。 Like: '-v' and '--version' in most cases the same, but requires different markers. 像:“-v”和“ --version”在大多数情况下是相同的,但是需要不同的标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM