我有这个代码:
"use strict";
import browserSync from "browser-sync";
import httpProxy from "http-proxy";
let proxy = httpProxy.createProxyServer({});
Run Code Online (Sandbox Code Playgroud)
我通过npm 安装babel-core并babel-cli全局安装.关键是当我尝试在终端上使用它编译时:
babel proxy.js --out-file proxified.js
Run Code Online (Sandbox Code Playgroud)
输出文件被复制而不是编译(我的意思是,它与源文件相同).
我在这里错过了什么?
我用的是需要挂钩的BabelJS(原名6to5)与运行节点的应用程序es6features:
// run.js
require("babel/register");
require("./app.js6");
Run Code Online (Sandbox Code Playgroud)
我打电话node run.js来运行我的app.js6.我需要安装BabelJS并提供run.js每个我想使用es6features项目.我更喜欢这样的电话nodejs6 app.js6.如何独立实现此系统(Unix和Windows)?
当我运行index.js时给出错误SyntaxError: Unexpected token import.虽然我使用babel将ES6转换为ES5.
的package.json
{
"name": "espract",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"build": "babel src -d lib"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.3.17"
}
}
Run Code Online (Sandbox Code Playgroud)
Person.js
'use strict';
module.exports = class Person {
constructor(firstname, lastname) {
this.firstName = firstname;
this.lastName = lastname;
}
greet() {
console.log(`Hello, ${ this.firstName } ${ this.lastName }`);
}
};
Run Code Online (Sandbox Code Playgroud)
index.js
import * as Person from './lib/Person';
//es class inherit Person
class Policeman extends Person {
constructor(firstname, …Run Code Online (Sandbox Code Playgroud) I'm having a problem when running jest test. I'm getting an import unexpected identifier
I have already tried by cleaning npm cache and installing npm babel jest, polyfill, preset-es2015. I've also read this trying some different configs here and there.
This is my babel.config.js
module.exports = {
presets: [
'@vue/app'
],
env: {
test: {
plugins: [
"transform-strict-mode",
"transform-es2015-modules-commonjs",
"transform-es2015-spread",
"transform-es2015-destructuring",
"transform-es2015-parameters"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
and my jest config in package.json
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
], …Run Code Online (Sandbox Code Playgroud) 我正在尝试建立一个基本的模块化程序,但是我似乎遇到了导入模块的问题.我尝试导入我的自定义模块,我收到以下错误:
(function (exports, require, module, __filename, __dirname) { import testStep from 'testStep';
^^^^^^
SyntaxError: Unexpected token import
Run Code Online (Sandbox Code Playgroud)
导致问题的代码:
testcase.js
import testStep from 'testStep';
testStep.hello();
Run Code Online (Sandbox Code Playgroud)
testStep.js
var testStep = {
hello: hello,
};
var hello = () => {
console.log('hello world');
};
export default {testStep};
Run Code Online (Sandbox Code Playgroud)
的package.json
{
"name": "rebuild-poc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.6.0"
},
"dependencies": {}
} …Run Code Online (Sandbox Code Playgroud)