Tag: babeljs

无法通过npm脚本运行babel“babel:command not found”

要开始我跑了: npm install –save-dev babel-cli npm install –save-dev babel-preset-es2015 npm install –save-dev babel-preset-stage-0 这是我的package.json: { "scripts": { "build": "babel src -d dist" }, "devDependencies": { "babel-cli": "^6.6.5", "babel-core": "^6.7.2", "babel-preset-es2015": "^6.6.0", "babel-preset-stage-0": "^6.5.0" } } 这是我的.babelrc文件: { "presets": ["es2015", "stage-0"] } 我的文件结构是这样的: – Root – src – client – server – test – dist – […]

是否可以在生产中使用require('babel / register)'

根据babel的正式文件, 不应该在生产中使用babel-node 。 有些人说,如果你不想在运行之前把你的ES6代码编译到ES5中,你可以使用babel/register而不是babel-node 。 但是babel-node没有在内部使用babel/register ? babel-node和require('babel/register');什么区别require('babel/register'); 。 是否可以使用require('babel/register'); 在生产?

错误:无法find预设“反应”安装时使用npm install –global babel-preset-react但工作没有全局标志

我使用npm install –global babel-cli安装了Babel CLI(版本6)。 然后我使用npm install –global babel-preset-react安装反应预设。 然后我将项目目录中的.babelrc文件设置为 { "presets": ["react"] } 当我尝试构build一个JSX文件时失败 Error: Couldn't find preset "react" at OptionManager.mergePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:310:17) at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:270:12) at OptionManager.addConfig (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:206:10) at OptionManager.findConfigs (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:347:16) at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:392:12) at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:191:75) at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:122:22) at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:42:16) at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:53:22) at Object.compile (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:62:12) 如果我安装的预设没有 – 全局标志(即安装在node_modules /文件夹本地),那么构build工程。 […]

在严格模式下的节点0.12.x const问题

我正在运行节点v0.12.7,并通过npm安装量angular器。 现在我试图用这个简单的教程来运行conf.js,并且在执行命令protractor conf.js时出现以下错误: [launcher] Process exited with error code 1 C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\index.js:25 const builder = require('./builder'); ^^^^^ SyntaxError: Use of const in strict mode. at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at Object.<anonymous> (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\built\protractor.js:3:17) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) 不能更新节点,因为它会产生依赖关系问题(我正在使用节点0.12.17的已经build好的项目上工作)。 在量angular器上使用–harmony标志不起作用。 […]

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" } } Person.js 'use strict'; module.exports = class Person { constructor(firstname, lastname) { this.firstName = firstname; this.lastName = lastname; } greet() { console.log(`Hello, […]

节点模块的根目录

我有一个漂亮的标准节点模块使用巴贝尔transpile我们的代码,然后输出到一个'lib'文件夹。 package.json将'main'指向'lib / index.js',这样人们可以只require('my-module') 但是,如果我有一个子目录(比如说我的模块/服务器),那么当他们使用我的模块时,他们必须require('my-module/lib/server') 。 我已经看到人们把后期制作步骤,将package.json复制到lib,但只是觉得哈克和错误的我。 在npm中有没有什么方法来指定一个主目录 ,从而我的模块的任何require()将从那个目录开始? 然后我可以让用户确实需要('我的模块/服务器')没有lib部分…

Webpack不能将ES6转换成ES5

我对Webpack很陌生。 我认为我做错了。 我想使用babel将ES6函数转换为ES5函数。 所以我做了一些研究,发现了babel-loader。 但是,我不知道我在做什么。 我运行npm install babel-loader –save-dev,它被添加到我的package.json中 // package.json { "name": "kanban", "version": "1.0.0", "description": "kanban", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "devDependencies": { "babel-core": "^6.3.21", "babel-loader": "^6.2.0", "html-webpack-plugin": "^1.7.0", "json-loader": "^0.5.4", "webpack": "^1.12.9" } } // webpack.config.js var path = […]

vscodedebuggingES6应用程序

我有VSCode 0.5.0。 我将compilerOptions标志设置为“ES6”,编辑器开始认识到我的ES6代码是正确的。 我已经安装了babel。 我的摩卡testing使用babel编译器,我的testing通过。 当我用babel-node启动它时,我的应用程序从命令行运行,没有任何问题。 当我从VSCode中debugging应用程序时,它将在没有ES6支持的情况下启动,并且应用程序因ES6语法问题而失败。 有没有debugging设置,我错过了打开?

React,babel,webpack不parsingjsx代码

webpack.config.js module.exports = { context: __dirname + "/app", entry: { javascript: "./app.js", html: "./index.html", }, resolve: { extensions: ['', '.js', '.jsx'] }, output: { filename: "app.js", path: __dirname + "/dist", }, module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loader: "babel-loader", }, { test: /\.html$/, loader: "file?name=[name].[ext]", }, ], }, } 的package.json { "name": […]

如何在Babel 6中使用babel-runtime?

我正在尝试创buildnpm模块,并且在官方的babeljs网站上找不到单个指令。 你如何使用babel-runtime软件包? 从名字我猜它应该被放置在package.json的“依赖”部分,对吧? 这里绝对没有信息: https : //github.com/babel/babel/tree/master/packages/babel-runtime 在这里find一个例子: https ://strongloop.com/strongblog/javascript-babel-future/但是当我运行“babel -h”时,它没有列出–optional作为一个有效的参数。