私はorg-babelにこのコードブロックを評価させるのに苦労しています
emacs v24.5
ノードv5.0.0
バベルノードv.6.6.5
#+ BEGIN_SRC js:cmd "babel-node" let arr = [1、2]; let [x、y] = arr; console.log(x); console.log(y); #+ END_SRC
出力は次のようになります
/ tmp / babel-3700Vaq / js-script-37003RN:2
let arr = [1、2]; ^^^ SyntaxError:ブロックスコープ宣言(let、const、function、class)は、strictモード以外ではまだサポートされていません exports.runInThisContext(vm.js:53:16)で Module._compile(module.js:404:25)で ローダー(/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:126:5) at Object.require.extensions。(無名関数)[.jsとして](/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:136:7) Module.load(module.js:356:32) Function.Module._load(module.js:311:12)で Function.Module.runMain(module.js:457:10)で /usr/local/lib/node_modules/babel-cli/lib/_babel-node.js:161:27 オブジェクトで。(/usr/local/lib/node_modules/babel-cli/lib/_babel-node.js:162:7) Module._compile(module.js:425:26)*
しかし、このソースブロックは問題ないようです
#+ BEGIN_SRC js:cmd "babel-node" const数= [10、20、30、50]; const multiplyBy10 = numbers.map(a => a * 10); console.log(multiplyBy10); #+ END_SRC #+結果: | 100 | 200 | 300 | 500 |
編集:「厳密な使用」で自己実行機能を追加
#+ BEGIN_SRC js:cmd "babel-node"
(関数xy(){
「厳格に使用」;
let arr = [1、2];
let [x、y] = arr;
console.log(x);
console.log(y);
})()
#+ END_SRC
#+結果:
出力は次のようになります
/ tmp / babel-13529OHt / js-script-13529MVq:6
let [x、y] = arr;
^
SyntaxError:予期しないトークン [
exports.runInThisContext(vm.js:53:16)で
Module._compile(module.js:404:25)で
ローダー(/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:126:5)
at Object.require.extensions。(無名関数)[.jsとして](/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:136:7)
Module.load(module.js:356:32)
Function.Module._load(module.js:311:12)で
Function.Module.runMain(module.js:457:10)で
/usr/local/lib/node_modules/babel-cli/lib/_babel-node.js:161:27
オブジェクトで。(/usr/local/lib/node_modules/babel-cli/lib/_babel-node.js:162:7)
Module._compile(module.js:425:26)で
編集:@ebpaのおかげで私はそれを解決することができました
npm install -g babel-preset-es2015
これは、自己実行関数ラッパーを持たないデフォルトのソースブロックを評価した後に得られる出力です。
/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:372
新しいエラーをスローします( "プリセットを見つけることができませんでした" + JSON.stringify(val)+ "ディレクトリに対して相対的" + JSON.stringify(dirname));
^
エラー:ディレクトリ「/ tmp / babel-270346ez」に関連するプリセット「es2015」が見つかりませんでした
/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:372:17
Array.map(ネイティブ)
OptionManager.resolvePresets(/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:364:20)
OptionManager.mergePresetsで(/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:348:10)
OptionManager.mergeOptionsで(/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:307:14)
OptionManager.initで(/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:465:10)
コンパイル時(/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:81:45)
ローダー(/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:126:14)
at Object.require.extensions。(無名関数)[.jsとして](/usr/local/lib/node_modules/babel-cli/node_modules/babel-register/lib/node.js:136:7)
Module.load(module.js:356:32)
編集:ターミナルを起動してbabel-nodeを実行しました
> require( 'babel-preset-es2015');
出力
エラー:モジュール 'babel-preset-es2015'が見つかりません
Function.Module._resolveFilename(module.js:337:15)で
Function.Module._load(module.js:287:25)で
Module.require(module.js:366:17)で
at require(module.js:385:17)
repl:1:1で
Object.exports.runInThisContext(vm.js:54:17)で
at _eval(/home/johnwind/.nvm/versions/node/v5.0.0/lib/node_modules/babel-cli/lib/_babel-node.js:102:26)
REPLServer.replEval(/home/johnwind/.nvm/versions/node/v5.0.0/lib/node_modules/babel-cli/lib/_babel-node.js:187:14)
バインド時(domain.js:280:14)
REPLServer.runBound [as eval](domain.js:293:12)で
編集:起動して実行するためのフォローアップ
編集:この投稿は私にこのパズルのピースへのいくつかの手がかりを与えました
https://phabricator.babeljs.io/T6723
http://discuss.babeljs.io/t/error-parsing-jsx-with-global-installation-babel-preset-react/59/6
編集:最後にローカルコピーをインストールすることで機能しました
$ mkdir local_babel $ cd local_babel $ npm init $ npm install --save-dev babel-cli $ npm install --save-dev babel-core $ npm install --save-dev babel-preset-es2015 $ npm install --save-dev babel-preset-stage-0 $ npm install --save-dev babel-preset-stage-1 $ npm install --save-dev babel-preset-stage-2 $ npm install --save-dev babel-preset-stage-3
babel-nodeのソフトリンクを作成しました
$ cd / usr / local / bin $ ln -s〜/ local_babel / node_modules / babel-cli / bin / babel-node.js org-babel-node
.zshrc
エクスポートnpm_config_prefix = $ HOME / .node_modules エクスポートPATH = $ PATH:$ HOME / .node_modules / bin
これを私のinit.elに追加しました
(setenv "NODE_PATH"
(連結
"/ home / johnwind / local_babel / node_modules" ":"
(getenv "NODE_PATH")
)
)
出力
#+ BEGIN_SRC js:cmd "org-babel-node --presets es2015" let arr = [1、2]; let [x、y] = arr; console.log(x); console.log(y); #+ END_SRC #+結果: :1 :2 :未定義
今のところ、babel-cli、babel-core、babel-preset-es2015のローカルコピーとグローバルコピーの両方があります。これは、リソースの浪費のようなものなので、これに頭を悩ませることはできませんでした。
しかし、それは機能します。
うまくいきませんでした。あなたはそれらを機能させることができましたか?もしそうなら、取られた手順を詳しく説明していただけませんか。
—
Johnathan Foong 2016年
@JohnathanFoong @wvxvwが意味し
—
Jordon Biondo 2016年
"use strict"なかったと思うので"strict"、試してみてください。
これは、「use strict」を追加した後に発生するエラーですSyntaxError:Unexpected token [at exports.runInThisContext(vm.js:53:16)at Module._compile(module.js:404:25)...
—
ジョナサン・フォン2016年
おそらく、そのコードを自己呼び出し関数にラップ
—
caisah 2016年
"use strict";し、最初に追加する必要があります。
"strict"ソースコードの最初の行を追加してみましたか?これはエラーが示唆しているようです。