SyntaxError: Unexpected token import
This question already has an answer here:
Update: In Node 9, it is enabled behind a flag, and uses the .mjs
extension.
node --experimental-modules my-app.mjs
While import
is indeed part of ES6, it is unfortunately not yet supported in NodeJS by default, and has only very recently landed support in browsers.
See browser compat table on MDN and this Node issue.
From James M Snell's Update on ES6 Modules in Node.js (February 2017):
Work is in progress but it is going to take some time — We're currently looking at around a year at least.
Until support shows up natively, you'll have to continue using classic require
statements:
const express = require("express");
If you really want to use new ES6/7 features in NodeJS, you can compile it using Babel. Here's an example server.
Unfortunately, Node.js doesn't support ES6's import
yet.
To accomplish what you're trying to do (import the Express module), this code should suffice
var express = require("express");
Also, be sure you have Express installed by running
$ npm install express
See the Node.js Docs for more information about learning Node.js.
Error: SyntaxError: Unexpected token import or SyntaxError: Unexpected token export
Solution: Change all your imports as example
const express = require('express');
const webpack = require('webpack');
const path = require('path');
const config = require('../webpack.config.dev');
const open = require('open');
链接地址: http://www.djcxy.com/p/46044.html
上一篇: 如何从ajax调用更新和发布复选框的值
下一篇: SyntaxError:意外的令牌导入