Tag: babeljs

es6导出/导入多个类 – instanceof返回false

test1.js export class ValidationError extends Error { constructor (msg) { super(msg) } } export class ServerError extends Error { constructor (msg) { super(msg) } } test2.js import * as errors from './test1' const inst = new errors.ValidationError('msg') console.log(inst instanceof errors.ValidationError) 当我运行test2输出是false ( true预期)。

Webpack不包括我们所有的js和jsx文件,甚至是那些在同一个目录下的文件

我们正在尝试升级使用WebPack构build的React.js应用程序。 在我们的升级中,我们正在从Webpack 1.0迁移到2.0,并且我已经对升级进行了“必要的”更改。 但是,当我查看包含的文件时,它正在构build和编译,它是以前包含的文件的一个非常小的规模。 例如,我们在React Flux Actions目录中有34个文件。 有些文件的.js扩展名是.jsx。 但是,在这34个文件中,只有1个出现在构build中。 另一个发生了什么事情33.这个扩展名是.js,但是那个目录下还有更多的.js文件。 我错过了什么? 这是我们的主要configuration文件。 var path = require('path'); var webpack = require('webpack'); var StringReplacePlugin = require("string-replace-webpack-plugin"); var Environment = require('./js/environment'); module.exports = { entry: [ './js' ], output: { path: path.join(__dirname, 'build'), filename: 'bundle.js', }, plugins: [ new StringReplacePlugin(), new webpack.LoaderOptionsPlugin({ options: { tslint: { emitErrors: true, […]

ES6dynamic导入和实例化类

我想弄清楚如何执行在ES6一个服务器端(与巴贝尔node.js)类的dynamic导入。 我想要有一些类似于Javareflection的function。 这个想法是导入一个特定的文件夹中的所有类,并dynamic地实例化它们。 所以举例来说,我可以在一个文件夹中声明多个类,如下所示: export default class MyClass { constructor(somevar) { this._somevar = somevar } //… //some more instance level functions here } 然后在我的应用程序的代码中的其他地方,我可以有一个函数,找出特定文件夹中的所有类,并试图instanciate他们: //somewhere else in my app instanciationFunction(){ //find all the classes in a specific folder var classFiles = glob.sync(p + '/path_to_classes/**/*.js', { nodir: true }); _.each(classFiles, async function (file) { console.log(file); var […]

在新机器上启动Ember项目时出错:意外的令牌导入,未定义

我在2台电脑上安装了Ember js项目,但是在安装新电脑时遇到问题。 我这样安装: git clone <repository-url> cd projectfolder npm install bower install ember serve 它编译,但在浏览器中,我看到这样的错误: event-factory.js:3 – 未捕获的SyntaxError:意外的令牌导入 application.js:1 – 未捕获的ReferenceError:define没有定义 似乎与巴贝尔一些错误。 我有这样的package.json { "name": "project", "version": "2.0.0", "description": "", "private": true, "directories": { "doc": "doc", "test": "tests" }, "scripts": { "build": "ember build", "start": "ember server", "test": "ember test" }, "repository": { "type": "git", […]

在ES2017与巴贝尔和JEST意外令牌导入

我尝试在我的项目中使用Jest和bablejs和ES2017,根据Jest Getting Started页面以及ES2017的Bablejsconfiguration,这是我的.babelrc文件: { "presets": ["es2017"], "env": { "test": { "presets": ["es2017"] } } } 和我的包json是: { "name": "", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "jest" }, "repository": { "type": "git", "url": "" }, "author": "", "license": "ISC", "bugs": { "url": "" }, "homepage": "", "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.0", "babel-jest": […]

asn1中意外的令牌(len)

我发布这主要是为了别人的好处,因为花了几个小时的研究来深入研究这个问题,我不认为它是与我们的应用程序隔离的。 我最近重新安装了所有npm包在我们的babelified应用程序,并开始在构build过程中出现错误,如“意外的令牌(len)”。 经过相当多的挖掘,我开始findconst,让一个名为asn1.js的包。

ES6中的JavaScript开发与debugging

我一直在试图find一种方法来编写ES6 JavaScript代码,具有实时debuggingfunction。 问题是,ES6代码需要在浏览器解释之前进行编译(易于使用babel),因此很难使用debugging断点。 我发现这两篇文章很有帮助: 如何debugging的-ES6-的NodeJS与- vscode debuggingES6-码在节点-JS 我的问题: 这些天,熟练的JavaScript开发人员正在做什么呢? 下面三个中的任何一个? 在ES6中编写,先用babel / webpack进行编译,然后尝试debugging新的和杂乱的ES5代码 以某种方式将ES6原始代码与转换后的ES5生成代码同步,使用源地图进行debugging工作 根本不写ES6代码

Babel 6不会传输我的代码

这是我的代码 require('babel-register') require('babel-polyfill') const Koa = require('koa'); const app = new Koa(); // logger app.use(async (ctx, next) => { const start = new Date; await next(); const ms = new Date – start; console.log(`${ctx.method} ${ctx.url} – ${ms}ms`); }); // response app.use(ctx => { ctx.body = 'Hello World'; }); app.listen(3000); Koa v2.0采用async/await的例子。 不幸的是它不工作。 我得到以下错误: app.use(async (ctx, […]

Javascript .contains()在Babel中是否可用于Node和React?

基本上寻找替代"jdklajsdf".indexOf('d') !== -1 ,与最新的巴别。 也用于数组。

Babelify和本地节点模块

当使用Babelify和Browserify时,有没有办法import本地节点模块(例如crypto , fs , path )? 例如: 'use strict'; import $ from 'jquery'; import fs from 'fs'; // <—— this line causes an error var data = JSON.parse(fs.readFileSync('foo.json', 'utf8')); $(document).ready(function () { // stuff }); 当我尝试运行它时,Browserify给了我这个错误: 错误:在parsingfile:/ home / vincent时尝试静态调用{ readFile: [Function: readFile], readFileSync: [Function: readFileSync], readdir: [Function: readdir], readdirSync: [Function: readdirSync] } /www/project1/resources/js/foo.jsparsing文件时:/home/vincent/www/project1/resources/js/foo.js 我也尝试了以下相同的结果: […]