2015-12-27 8 views
8

काम नहीं कर रहा है herebabel-cli स्थापित करने के लिए मैंने निर्देशों का पालन किया। मैं निर्देशिका मैं में इसे चलाने के लिए चाहते हैं, उसमें मेरी package.json को "build": "babel src -d lib" जोड़ा हालांकि, चल रहा है पर, मैं इस त्रुटि मिलती है:।एनपीएम स्क्रिप्ट से बेबेल-क्ली चलाना

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 

मैं एक नुकसान में हूँ। स्रोत उत्पन्न नहीं होना चाहिए? 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 कोड युक्त एक फ़ाइल जगह, कोलाहल होगा खुशी से भागो, लेकिन आउटपुट इनपुट के समान (लगभग) होगा।


यह बेबेल-क्ली के साथ उठने और दौड़ने का एक त्वरित उदाहरण है।

एक परियोजना बनाएं, फिर कोलाहल-CLI पैकेज और ES2015 पूर्व निर्धारित स्थापित:

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

अगला संपादित package.json:

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

सूचना है कि NPM लिपियों में आदेश है कि करने के लिए थोड़ा अलग है babel homepage पर, जहां तक ​​हम इसे स्थापित प्रीसेट का उपयोग करने के लिए कह रहे हैं।

mkdir src && cd src 
touch main.js 

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 // या अन्य आदेशों को

काम करना चाहिए
संबंधित मुद्दे