node.js中意外保留字导入 [英] unexpected reserved word import in node.js
问题描述
我正在尝试运行node.js后端服务器。我在Node.js文件中导入时收到错误意外保留字
。
I'm trying to run node.js backend server. I've received error unexpected reserved word
on import in Node.js file.
文件中的行 core.module.js
是:
'use strict';
import lodashMixins from './lodashMixins.js'
... other imports and configurations ...
我启动简单的命令: node core.module.js
这并不罕见的错误,但通常会发生在其他图书馆。我还没有看到Node.js的解决方案我应该如何解决这个问题?我正在使用Windows Server。
It's not uncommon error, but usually it happens with other libraries. I haven't seen solution for Node.js. How should I fix this? I'm using Windows Server.
编辑:我发现它是ES6,但是如何启动它?它看起来像后端的应用程序,但我不知道应该使用什么命令来启动它没有错误。
I've find out that it's ES6, but how could I launch it? It looks like backend for the application, but I have no idea what command should I use to launch it without errors.
推荐答案
import
关键字是中的nofollow noreferrer>模块,以及 export
等几个规格。
The import
keyword is part of the modules feature in ECMAScript 2015, along with export
and a few other specifications.
它现在在NodeJS中本来没有实现,即使是最新版本(v0.12.7),也没有在ES2015更友好的iojs中支持。
It is currently not implemented natively in NodeJS, even on the lastest version (v0.12.7), nor is it supported in the ES2015 "friendlier" fork iojs.
你将需要使用一个转换器来使其工作。
You will need to use a transpiler to get that to work.
尽管存在一个<$ c,但它仍然不支持最新版本(v5.8) $ c> - harmony_modules 标志,什么也不做任何操作 。最好的方法是使用babel,如这里和此处
[edit] it's still unsupported in the latest version (v5.8) despite the existence of an --harmony_modules
flag, which does nothing. Your best run is to use babel, as explained here and here
这篇关于node.js中意外保留字导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!