2015-12-27 19 views
8

をインストールするには、hereという指示に従ってください。私はそれを実行したいディレクトリ内の私のpackage.jsonに"build": "babel src -d lib"を追加しかし、実行している上、私はこのエラーを取得:。npmスクリプトからbabel-cliを実行できない

npm run build 

> [email protected] build /Users/richard/src/ipfs-readme-standard 
> babel src -d lib 

src doesn't exist 

npm ERR! Darwin 14.5.0 
npm ERR! argv "/Users/richard/.nvm/versions/node/v5.0.0/bin/node" "/Users/richard/.nvm/versions/node/v5.0.0/bin/npm" "run" "build" 
npm ERR! node v5.0.0 
npm ERR! npm v3.5.2 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] build: `babel src -d lib` 
npm ERR! Exit status 2 
npm ERR! 
npm ERR! Failed at the [email protected] build script 'babel src -d lib'. 
npm ERR! Make sure you have the latest version of node.js and npm installed. 
npm ERR! If you do, this is most likely a problem with the ipfs-readme-standard package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  babel src -d lib 
npm ERR! You can get information on how to open an issue for this project with: 
npm ERR!  npm bugs ipfs-readme-standard 
npm ERR! Or if that isn't available, you can get their info via: 
npm ERR!  npm owner ls ipfs-readme-standard 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /Users/richard/src/ipfs-readme-standard/npm-debug.log 

私は途方に暮れてよ。 srcを生成してはいけませんか? babeljs.ioには、私が行方不明になっていることに特別なステップはありません。

答えて

24

Shouldn't src be generated?

これは、変換するスクリプトを含むフォルダです。それが存在しなければ、あなたが掲示したエラーをバベルが投げます。

また、それはあなたにリンクされたページの下部に言っていることに注意してください:

Pre-6.x, Babel enabled certain transformations by default. However, Babel 6.x does not ship with any transformations enabled. You need to explicitly tell it what transformations to run. The simplest way to do this is by using a preset, such as the ES2015 Preset.

これは、あなたがsrcディレクトリを作成し、その中でES6コードを含むファイルを配置した場合でも、バベルがすることを意味します喜んで実行されますが、出力は入力とほぼ同じです。


これは、babel-cliを起動して実行する方法の簡単な例です。

バベル-cliのパッケージとES2015のプリセットをインストールし、プロジェクトを作成します。

mkdir babeltest && cd babeltest 
touch package.json 
npm install babel-cli babel-preset-es2015 --save-dev 

次の編集package.json:NPMスクリプト内のコマンドは、それとは若干異なること

{ 
    "name": "my-project", 
    "version": "1.0.0", 
    "scripts": { 
    "build": "babel src -d lib" 
    }, 
    "scripts": { 
    "build": "babel --presets es2015 src -d lib" 
    }, 
    "devDependencies": { 
    "babel-cli": "^6.0.0" 
    } 
} 

お知らせbabel homepageにあります。インストールされているプリセットを使用するように指示されている限りです。 main.jsで

mkdir src && cd src 
touch main.js 

追加:

[1,2,3].map(x => x * x) 

が続いNPM経由バベルを実行します。

npm run build 

と出力を検査

次はsrcディレクトリ内のファイルを作りますlib/main.js

"use strict"; 

[1, 2, 3].map(function (x) { 
    return x * x; 
}); 
0

あなたノードモジュールがインストールされていないときは、また、単に

npm install 

を実行し、

、あなたは、インターネットからコードをダウンロードして、すぐにコードを実行しようとした場合、それは上記のエラーをスローし、このエラーが出ます

npm run build //またはその他のコマンドが動作するはずです

関連する問題