[英]Unexpected token import using node
I have a simple file numeral.js that I'm trying to test with mocha running through node. 我有一个简单的numerical.js文件,正在尝试通过节点运行的mocha进行测试。
An afternoon of searching however has left me at the first hurdle. 一个下午的搜寻却使我无处可去。
Numeral.js: Numeral.js:
"use strict";
exports.__esModule = true;
exports.numeral = function (id) {
return "";
};
test.js test.js
import {numeral} from './numeral.js'
var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1,2,3].indexOf(4));
});
});
});
I navigate to the folder (that has mocha set up as test in the packages.json) and run npm test . 我导航到文件夹(在packages.json中将mocha设置为test)并运行npm test 。 That throws out a: 这抛出了一个:
C:\Users\matt\Documents\mocha\test\test.js:1
(function (exports, require, module, __filename, __dirname) { import {numeral} from './numeral.js'
^^^^^^
SyntaxError: Unexpected token import
How am I going so wrong? 我怎么会这么错?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.