相关疑难解决方法(0)

Babel文件未经转换即被复制

我有这个代码:

"use strict";

import browserSync from "browser-sync";
import httpProxy from "http-proxy";

let proxy = httpProxy.createProxyServer({});
Run Code Online (Sandbox Code Playgroud)

我通过npm 安装babel-corebabel-cli全局安装.关键是当我尝试在终端上使用它编译时:

babel proxy.js --out-file proxified.js
Run Code Online (Sandbox Code Playgroud)

输出文件被复制而不是编译(我的意思是,它与源文件相同).

我在这里错过了什么?

javascript babeljs

106
推荐指数
2
解决办法
4万
查看次数

如何运行启用ES6功能的Node.js应用程序?

我用的是需要挂钩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)?

javascript node.js ecmascript-6 babeljs

69
推荐指数
5
解决办法
8万
查看次数

SyntaxError:意外的令牌导入

当我运行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)

javascript node.js ecmascript-6 babeljs

14
推荐指数
0
解决办法
9万
查看次数

Import Unexpected identifier + SyntaxError: Unexpected string

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)

javascript vue.js jestjs babeljs

10
推荐指数
1
解决办法
2005
查看次数

Babel ES6导入错误,SyntaxError:意外的令牌导入

我正在尝试建立一个基本的模块化程序,但是我似乎遇到了导入模块的问题.我尝试导入我的自定义模块,我收到以下错误:

(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)

javascript node.js babeljs

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

babeljs ×5

javascript ×5

node.js ×3

ecmascript-6 ×2

jestjs ×1

vue.js ×1