我正在使用带有webstorm的babeljs。 巴贝尔的论点是:
- source-maps --out-file $ FileNameWithoutExtension $ -compiled.js $ FilePath $
我有以下es6代码:
export function primeFactors(num) {
let res = [];
let n = 2;
while (num > 1) {
while(num%n ===0) {
res.push(n);
}
n++;
}
return res;
}
它被转换为
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.primeFactors = primeFactors;
function primeFactors(num) {
var res = [];
var n = 2;
while (num > 1) {
while (num % n === 0) {
res.push(n);
}
n++;
}
return res;
}
//# sourceMappingURL=numUtils-compiled.js.map
我有一个需要文件的脚本
import {primeFactors} from "lib/numUtils";
它被转化为
"use strict";
var _libNumUtils = require("lib/numUtils");
//# sourceMappingURL=ex3-compiled.js.map
当我使用nodejs运行脚本时,我得到了
export function primeFactors(num) { ^^^^^^ SyntaxError: Unexpected reserved word at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object. (J:\webstorm_workspace\euler\ex3-compiled.js:3:20) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10)
可能是什么原因?