2

I am a newbie in JS and I have some troubles running the test server (like: node app.js ..or iojs app.js) with the new ECMA6 syntax (using import and export)... here is the sample code I am using trying to achive that and the error the server is returning :

    <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>

and in app.js the following simple code :

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('#/');
}

then o recive the following error screen when trying to execute the test server:

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

Any advice on where my fault is would be great.. Thank you all in advance

Nick Iliev
  • 9,610
  • 3
  • 35
  • 89
  • 1
    Why are you placing things in ` – Bergi Sep 08 '15 at 12:01
  • try putting `"use strict";` on top of your file – astronaut Nov 07 '15 at 10:51
  • Possible duplicate of [unexpected reserved word import in node.js](http://stackoverflow.com/questions/32346886/unexpected-reserved-word-import-in-node-js) – Paul Sweatte Jan 19 '17 at 19:30

0 Answers0