Tag: babeljs

Webstorm意外的令牌导出

我在Webstorm中有一个“意外的令牌导出”问题,尚未被其他StackOverflowpost解决。 基本上我正在尝试使用下面的package.json和bar.js代码的导入/导出模块function。 我正在使用Node.js 5x,Babel 6,并且我有一个File Watcher设置来实现Babel变换。 代码应该说明一切,我很感激关于如何解决它的任何想法。 再次,我已经尝试了其他的StackOverflowbuild议,在这一点上没有运气。 //bar.js 'use strict'; export class Bar{ constructor(){ this.tempish = 'allo'; } } //bar-compiled.js 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Bar = exports.Bar = function […]

错误:用摩卡testing时找不到模块

我使用babeljs来编写一个RPG引擎库。 我有两个文件: dice.js import assert from 'assert'; import Random from 'random-js'; export default class Dice { constructor(maxNumber) { assert(typeof(maxNumber) === "number", "maxNumber must be a number"); this._mt = Random.engines.mt19937(); this.minNumber = 1; this.maxNumber = maxNumber; } makeThrow() { this._mt.autoSeed(); return Random.integer(this.minNumber, this.maxNumber)(this._mt); } } throwManager.js import assert from 'assert'; import Dice from 'dice'; export default […]

如果不是来自NPM的依赖关系,NPM安装不会触发babel构build

例如,如果在我的package.json中,我有这样的: "dependencies": { "cacheman": "2.1.0" } 它工作,当我做npm安装时,它会触发cacheman里面的构build脚本。 但是,如果我这样做: "dependencies": { "cacheman": "https://github.com/cayasso/cacheman.git" } 它不会工作。 npm install不会触发cacheman的构build过程。 这是为什么?

为什么在ES6模块中导出的对象有未定义的方法?

我在ES6模块中定义了一个ES6类,用于导出该类的一个实例 : class MyObject { constructor() { this.propertyA = 1; this.propertyB = 2; } myMethod() { doStuff(); } } var theInstance = new MyObject(); export default theInstance; 当我导入这个模块时, myMethod是undefined : import * as theObject from './my/module'; theObject.myMethod(); // Error! undefined is not a method. 在构造函数中定义的属性确实存在。 仿佛对象的原型被排除在外,只有其成员被导出。 我要求'babel/register' 。 为什么导出这个对象不能正常工作?

Heroku找不到`babel-core / register`

我正在使用NodeJS构build一个小型的url-shortener应用程序。 我在ES6中编写代码,使用导入Babel的索引文件,然后是我的服务器: require('babel-core/register'); require('./server.js'); 这在localhost上运行绝对正常,所有的ES6代码都能正常工作。 但是,当我成功地部署到Heroku,我收到一个应用程序错误,以下显示在heroku日志 – tail -a shortenthisurl: 2016-02-06T12:31:14.074071+00:00 heroku[slug-compiler]: Slug compilation started 2016-02-06T12:31:14.074080+00:00 heroku[slug-compiler]: Slug compilation finished 2016-02-06T12:31:13.936954+00:00 heroku[api]: Deploy f576f69 by rory88@gmail.com 2016-02-06T12:31:13.936991+00:00 heroku[api]: Release v17 created by rory88@gmail.com 2016-02-06T12:31:14.230327+00:00 heroku[web.1]: State changed from crashed to starting 2016-02-06T12:31:15.215417+00:00 heroku[web.1]: Starting process with command `node index.js` 2016-02-06T12:31:16.816525+00:00 app[web.1]: module.js:341 2016-02-06T12:31:16.816534+00:00 app[web.1]: throw […]

导入与需求与巴贝尔节点

我想要在一个文件中导入一个类: "use strict"; import models from "../model"; class Foo { bar() { } } export default new Foo(); 它使用导入时,如: import Foo from "./foo"; console.log(Foo.bar); // [Function bar] 问题是,使用require来给我定义: var Foo = require("./foo"); console.log(Foo.bar); // undefined 而Foovariables似乎是一个空的类。 为什么? 这是怎么回事?

无法parsing'babel-loader'

我正在尝试configuration我的第一个节点反应的应用程序。 我不断收到一个错误,说“无法parsingbabel-loader”。 用Googlesearch这个错误,我发现了一些不起作用的build议。 首先是将以下内容添加到我的webpack.config.js中 // resolveLoader: { // modulesDirectories: '/usr/local/lib/node_modules' // }, 尝试产生一个错误,说: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. – configuration.resolveLoader has an unknown property 'modulesDirectories'. These properties are valid: object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, […]

如果没有大括号,请进入

if (true) { let x = 5 } 按预期工作(没有语法错误),但是 if (true) let x = 5 throws SyntaxError: Unexpected strict mode reserved word节点4.1.0和babel中SyntaxError: Unexpected strict mode reserved word 这是预期的行为? 我知道这是一个愚蠢的例子。 我只是想知道这是一个错误或没有。

为什么我的ES6(使用Babel)类说`this`在实例方法中是未定义的?

我使用Hapi.JS在Node中构build应用程序。 我有一个authentication插件的类,给我各种各样的问题。 当我试图从类的方法中引用this ,我得到一个错误,说this是未定义的。 为什么发生这种情况? 摘录: class OAuth { constructor () {} register (server, err, next) { this.server = server; this.registerRoutes(); } registerRoutes () { console.log(this.server.route); this.server.route([ { method: 'POST', path: '/oauth/token', config: { auth: false, handler: function(request,reply){ console.log("test"); reply("test"); } } }, { method: 'GET', path: '/test', config: { auth: false, handler: function(request,reply){ console.log("test"); […]

RollupJS`解决失败:错误:无法find模块'babel-runtime'`

汇总-误差示例 说明汇总的(可能的)问题。 我错过了什么吗? 这里有一个最小configuration的项目来重现我遇到的“问题”。 问题似乎只是无关的命令行日志logging,而不影响捆绑本身; 即捆绑被正确和准确地创build。 该项目显示输出: $ ./node_modules/.bin/rollup -c rollup.js node_modules/nan resolve failed: { Error: Cannot find module 'babel-runtime' at Function.Module._resolveFilename (module.js:472:15) at Function.requireRelative.resolve (/Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/require-relative/index.js:30:17) at resolve (/Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/modify-babel-preset/lib/serialize.js:25:26) at findAndRemove (/Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/modify-babel-preset/lib/serialize.js:67:11) at /Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/modify-babel-preset/lib/serialize.js:111:13 at Array.map (native) at loadPreset (/Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/modify-babel-preset/lib/serialize.js:103:29) at module.exports (/Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/modify-babel-preset/index.js:97:19) at Object.<anonymous> (/Users/jkalis/Pro/QL/WebCore/luxui/rollup-testing/node_modules/babel-preset-es2015-rollup/index.js:3:18) at Module._compile (module.js:573:32) code: 'MODULE_NOT_FOUND' } babel-runtime 重现这个命令是: npm […]