Tag: babeljs

伊斯坦布尔与巴贝尔有什么关系?

我正在尝试将代码覆盖范围添加到从ES2015转换的现有库中。 我似乎在做一切正确的事情。 我的生成文件读取 test: .FORCE export NODE_ENV=test babel *.js –out-dir lib nyc mocha 而我的babelrc读取 { "presets": ["es2015"], "sourceMaps": true, "env": { "test": { "plugins": ["istanbul"] } } } 而我的package.json包括 "nyc": { "include": [ "**/*.js" ], "require": [ "babel-register" ], "sourceMap": false, "instrument": false } 然而,我的testing运行后,输出简单地读取: ———-|———-|———-|———-|———-|—————-| File | % Stmts | % Branch | % […]

babel-preset-env不能与webpack-dev-server v2.2.0-rc.0一起使用

我正在尝试设置` webpack 2和babel-preset-env 。 我有以下的基本configuration: const config = require('./config'); const path = require('path'); module.exports = { devtool: 'source-map', performance: { hints: false }, entry: [ './src/index.js', ], output: { path: path.join(__dirname, '../dist'), publicPath: '/dist/', filename: 'app.js' }, plugins: [], module: { loaders: [ { test: /\.js$/, loader: 'babel-loader', exclude: ['/node_modules/'], query: { 'presets': [['env', { […]

使用Gulp with Babel错误导入

我想用babel来编译我已经用一个简单的文件(routes / users.js)尝试的ES6代码,如下所示 import express from 'express'; var router = express.Router(); /* GET users listing. */ router.get('/', (req, res, next) => { res.send('respond with a resource'); }); export default router; 我已经添加到吞咽文件以下 gulp.task('esconverter', () => { return gulp.src('routes/users.js') .pipe(babel({ presets: ['es2015'] })) .pipe(gulp.dest('dist')); }); 我已经将任务添加到默认 gulp.task('default', ['esconverter' ,'nodemon'], () => { console.log("Done"); }); 当我运行它(gulp.js)时,我得到了以下错误 /Users/i0/Webs/blog10/bl/routes/users.js:1 (function […]

为什么babel-node-debug不能识别导入命令?

» babel-node-debug –presets es2015 ./updateChains.js Node Inspector v0.12.10 Visit http://127.0.0.1:8080/?port=5858 to start debugging. Debugging `./scripts/updateChains.js` Debugger listening on [::]:5858 /mysite/updateChains.js:1 (function (exports, require, module, __filename, __dirname) { import dotenv from 'dotenv'; 我认为它使用节点检查员v0.12.10是它的一部分,但我不知道有什么build议吗?

TypeError:f在Node中的Babel Transpilation之后不是函数

我有这个networking应用程序运行在节点上。 代码在ES5中。 现在我将代码更改为ES6并使用Babel Transpilation。 编译运行正常,但我在启动服务器时遇到下面的错误: *TypeError: _routes2.default.init is not a function* server.js代码引用routes.js。 server.js代码: import express from 'express'; import routes from './routes'; let app = express(); routes.init(app); //Issue line app.set('view engine','vash'); app.listen(4000, function(){ console.log("server listening on port 4000"); }); routes.js代码: import homeController from '../controllers/homeController'; class routes{ init(app){ app.get('/', homeController.index); } } export default routes; 转发的server.js代码: 'use […]

如何debugging在es6 / es7中编写的node.js后端?

我想直接debugginges7源代码。 我发现只有一个工作方式来debugging已经发生的es5代码,但这是非常不方便的。 我尝试了babel-node –inspect my_es7_file.js ,但它不起作用。 此外babel-node-debug也不起作用。 有我想要debugging的代码示例: import path from 'path'; const run = async filename => { console.log('filename', filename); await new Promise(resolve => setTimeout(resolve, 100)); debugger; await new Promise(resolve => setTimeout(resolve, 100)); const newPath = path.resolve(__dirname, filename); console.log('newPath', newPath); return newPath; } run('hello.js').then(process.exit); 这个代码运行良好,当我运行它使用babel节点 UPD我不喜欢Webstorm和VS Code。 我想在Atom中编写代码并在chrome开发工具中进行debugging。

模块构build失败:ReferenceError: /app/src/index.js:未知选项:/app/node_modules/react/react.js.Children

我的项目失败,在heroku上的标题错误消息,但它在本地工作。 这是我的webpack.config.js : module.exports = { entry: [ './src/index.js' ], output: { path: __dirname, publicPath: '/', filename: 'bundle.js' }, module: { loaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', query: { presets: ['react', 'es2015', 'stage-0'] } }] }, resolve: { extensions: ['.jsx', '.js'] }, devServer: { historyApiFallback: true, contentBase: './' } }; 这是package.json : { […]

与babel.js一起使用gulp-watch

下面是一个Gulp ES6的编译任务。 它工作正常,但我试图用gulp-watch插件replacegulp.watch,以便捕获新文件。 问题是,gulp-watch并没有给我gulp.watch做的callback,我不知道该怎么办。 这是我原来的工作任务: var gulp = require('gulp'), rename = require('gulp-rename'), plumber = require('gulp-plumber'), gprint = require('gulp-print'), notify = require('gulp-notify'), babel = require('gulp-babel'); gulp.task('default', function() { return gulp.watch('../**/**-es6.js', function(obj){ if (obj.type === 'changed') { gulp.src(obj.path, { base: './' }) .pipe(plumber({ errorHandler: function (error) { /* elided */ } })) .pipe(babel()) .pipe(rename(function (path) { path.basename […]

预期testing不适用于ES6 / ES2015 Set对象

问题 下面的testing应该会失败,但是正在通过: it('should fail', () => { const actual = new Set('a'); const expected = new Set('b'); expect(actual).toEqual(expected); }); 背景和问题 我使用npm的expect包 。 我使用Babel 5来使用Set 。 我正在使用节点5,所以使用的集应该是本地的 。 我做错了什么,或者它看起来像在处理集的方式expect包中的错误? 我已经在包裹上贴了一个问题,因为我不确定。

用于在node_modules中编译模块的Webpackconfiguration

我的webpack / babelconfiguration有问题。 我已经安装我的组件库(es6模块没有webpackconfiguration里面)作为node_module。 而在这种情况下,它不工作 – 我得到了'意外的令牌导入'错误(巴贝尔不会esp代码esp) 但是,如果我将外部文件夹链接到node_modules(npm链接./../../component-repository),那么它工作正常,没有任何错误。 我花了很多时间,仍然无法解决这个问题。 主要问题是如何在各个项目之间共享反应组分。 我的想法是将它们添加为依赖项。 编辑:如何设置webpack&babel项目从node_modules文件夹编译ES6模块? npm链接到兄弟文件夹的解决scheme不适用于生产。 编辑2:为什么我保持在模块es6代码的原因是,在本地环境我想npm链接兄弟文件夹与组件(我可以编辑组件,然后提交更改到他们的存储库)。 我共享3个项目之间的组件。 但在生产中,我想从git仓库自动安装它们作为依赖 本地环境的结构: 组件(也是独立的git仓库) PROJECT1 node_modules 组件(从../../components链接) 项目2 node_modules 组件(从../../components链接) 生产结构: PROJECT1 node_modules 组件(作为从Git仓库的依赖)