SofDroid SofDroid - 1 year ago 1368
Node.js Question

Node.js - SyntaxError: Unexpected token import

I don't understand what is wrong.
Node v5.6.0
NPM v3.10.6

My code:

(function (exports, require, module, __filename, __dirname) { import express from 'express';


SyntaxError: Unexpected token import
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:140:18)
at node.js:1001:3

Answer Source

While import is indeed part of ES6, it is unfortunately not yet supported by any native environments, Node or browser.

See browser compat table on MDN and this Node issue.

Until support shows up natively, you'll have to continue using classic require statements:

const express = require("express");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download