2015-12-27 15 views
8

babel-cli'u yüklemek için here yönergelerini takip ettim. Ben bunu çalıştırmak istediğiniz dizinde benim package.json için "build": "babel src -d lib" eklendi Ancak, işleyiş ile ilgili, bu hatayı alıyorum:. Ben bir kayıp amNFS komut dosyasından çalışan babel-cli çalıştırılıyor

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 oluşturulmamalıdır? Babeljs.io'da eksik olduğum için fazladan bir adım yok.

cevap

24

Shouldn't src be generated?

Bu, nakledilmek istediğiniz komut dosyasını içeren klasördür. Eğer yoksa, babel gönderdiğiniz mesajı atar.

Ayrıca sayfanın alt kısmında ne yazdığını not almak size bağlı:

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.

Bunun anlamı bir src dizini oluşturmak ve içinde ES6 kodunu içeren bir dosya yerleştirmek bile, Babel olacak o Mutlu bir şekilde çalışır, ancak çıktı (neredeyse) girişle aynı olacaktır.


Bu kalk ve babel-cli ile çalışan nasıl hızlı bir örnektir.

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

Sonraki düzenlemeyi package.json: npm komut komut buna biraz farklı olduğunu

{ 
    "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" 
    } 
} 

Bildirimi

sonra babel-cli paketi ve ES2015 ön ayarını yüklemek, Proje oluşturma babel homepage üzerinde, yüklü önayarları kullanmasını söyledik. main.js ise

mkdir src && cd src 
touch main.js 

ekleyin::

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

Sonra NPM aracılığıyla Babel çalıştırın:

npm run build 

Ve çıkışını kontrol

Sonraki src dizininde bir dosya yapmak lib/main.js

"use strict"; 

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

sizin düğüm modülleri takılı değilken sadece koşmak, internetten kod indirmek ve hemen, yukarıdaki hata atıyor kodu çalıştırmayı deneyin olursa da, bu hatayı alabilirsiniz

npm install 

ve sonra

npm run build // veya diğer komutlar çalışmalıdır

İlgili konular