私はJSの初心者で、新しいECMA6構文(インポートとエクスポートを使用)でテストサーバー(ノードapp.js ..またはiojs app.jsなど)を実行するのに問題があります...これがサンプルコードですそれを達成しようとしていて、サーバーが返すエラー:
<script>
System.config({
baseURL:"/",
transpiler: "babel",
babelOptions: {
"optional": [
"runtime"
]
},
paths: {
"npm:*": "node_modules/*",
"bower:*": "bower_components/*"
},
map: {
"babel": "npm:babel-core/browser.js",
"sammy": "bower:sammy/lib/sammy.js",
"jquery":"bower:jquery/dist/jquery.js",
"handlebars": "bower:handlebars/handlebars.js"
}
});
</script>
<script type="text/javascript">
System.import('app.js')
.then(function(module) {
module.init('#content');
});
</script>
そして app.js では、次の簡単なコード:
import $ from 'jquery';
import sammy from 'sammy';
import homeController from './controllers/homeController.js';
export function init (element) {
var sammyApp = Sammy(element, function() {
this.get('#/', homeController.load);
});
sammyApp.run('#/');
}
次に、テスト サーバーを実行しようとすると、次のエラー画面が表示されます。
D:\TELERIK\JavaScript-Apps\exam-prepar-evlogi>iojs app.js
D:\TELERIK\JavaScript-Apps\exam-prepar-evlogi\app.js:1
(function (exports, require, module, __filename, __dirname) { import $ from 'j
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:448:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:471:10)
at startup (node.js:117:18)
at node.js:948:3
私のせいがどこにあるかについてのアドバイスは素晴らしいでしょう..すべて事前にありがとう