Tag: babeljs

'babel-core / register'vs'babel-register'

我们可以使用“babel-register”实时传输资源 https://babeljs.io/docs/usage/require/ 但我无法validation哪一个是使用的: require('babel-core/register') 要么 require('babel-register') 谁知道? 谢谢

未知选项:… / .babelrc.presets

我正在使用Babel 6 for es2015,并且需要使用babel-preset-es2015和babel-preset-react 。 我在.babelrc添加了presets属性,但是它给我一个错误: ERROR in ./src/client/entry.js Module build failed: ReferenceError: [BABEL] /Users/brick/Dropbox/learncoding/node.js/isomorphic/src/client/entry.js: Unknown option: /Users/brick/Dropbox/learncoding/node.js/isomorphic/.babelrc.presets at Logger.error (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/logger.js:58:11) at OptionManager.mergeOptions (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29) at OptionManager.addConfig (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:107:10) at OptionManager.findConfigs (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:35) at OptionManager.init (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:12) at File.initOptions (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/index.js:147:75) at new File (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/file/index.js:137:22) at Pipeline.transform (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-core/lib/transformation/pipeline.js:164:16) at transpile (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-loader/index.js:12:22) at Object.module.exports (/Users/brick/Dropbox/learncoding/node.js/isomorphic/node_modules/babel-loader/index.js:69:12) @ multi main 我的.babelrc文件是: { "presets": […]

如何设置Babel 6与节点JS在我的服务器端代码中使用ES6?

我已经阅读了多次提供的文档: Node API Babel 6 Docs 我开始学习pg-promise,遵循“按示例学习”教程,并且倾向于使用ES6和通过Babel转储到ES5,但是我不确定一些事情: 在安装babel-core之后,我将使用什么预设以及在哪里/如何configuration此function? 我不清楚我把哪个文件放在文档里: require(“babel-core”)。transform(“code”,options); 进入和代码的哪些部分是占位符。 当我使用这个代码时,我是否只是在某处使用它,然后我可以在其他文件中使用ES6? 这将如何实现? 我读了这个.babelrc文件,并想确认如果实际的文件名是“.babelrc”,或者如果这只是文件的扩展名,并在哪里与我的项目的根目录,我把该文件..以及如何做我链接到它? 如果我使用pg-promise ,我应该使用ES6和Babel,或者运行:npm install,如pg-promise的Testing部分中所述,是否足够,并尝试使用ES6来创build更多的问题? 如果需要在我的服务器端开发期间出现,我希望利用let和const。 是否有节点+ babel + pg-promise服务器设置的标准文件结构? 编辑值得注意的是,我也阅读了巴巴节点的JS节点 ,看到使用这个应该避免。 最后的答案在底部对我来说没有意义,因为我遇到了类似的问题,因为我根据Babel提供的实际文档而遇到麻烦。

使用babel时意外的保留字'import'

在我的NodeJSv4.1.1代码中使用Babel。 得到了要求挂钩在: require("babel-core/register"); $appRoot = __dirname; module.exports = require("./lib/controllers/app"); 在随后的lodaded .js文件中,我正在做: import { Strategy as LocalStrategy } from "passport-local"; 但是,这在CLI中产生以下错误: import { Strategy as LocalStrategy } from "passport-local"; ^^^^^^ SyntaxError: Unexpected reserved word at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:413:25) at loader (/Users/*/Documents/Web/*/node_modules/babel-core/node_modules/babel-register/lib/node.js:128:5) at Object.require.extensions.(anonymous function) [as .js] (/Users/*/Documents/Web/*/node_modules/babel-core/node_modules/babel-register/lib/node.js:138:7) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at […]

如何阻止babel从“this”到“undefined”

编辑 :这不是关于脂肪箭头 。 这也不是传递给一个IIFE 。 这是一个翻译相关的问题。 所以我为我正在开发的一个小应用程序创build了一个简单的pub-sub。 我写在ES6使用传播/rest和保存一些头痛。 我用npm和gulp来设置它,但它却让我发疯。 我做了一个浏览器库,但意识到它可以在任何地方使用,所以我决定让Commonjs和AMD兼容。 这里是我的代码的修剪版本: (function(root, factory) { if(typeof define === 'function' && define.amd) { define([], function() { return (root.simplePubSub = factory()) }); } else if(typeof module === 'object' && module.exports) { module.exports = (root.simplePubSub = factory()) } else { root.simplePubSub = root.SPS = factory() } }(this, function() { […]

Babelify在从node_modules导入模块时抛出ParseError

我正在与Babelify和Browserify合作 。 另外,我正在使用节点模块系统的ES6风格的模块function。 我想把所有我自己的模块放到node_modules/libs 。 例如: test.js在node_modules/libs export default () => { console.log('Hello'); }; main.js (将被编译为bundle.js ) import test from 'libs/test'; test(); 之后,我用这个命令将上面的代码编译到bundle.js : browserify -t babelify main.js -o bundle.js 但不幸的是,我有一些错误: export default () => { ^ ParseError: 'import' and 'export' may appear only with 'sourceType: module' 目录结构: [test] `– node_modules │ `– libs │ […]