Tag: babeljs

Babel-Node不断尝试转换.stylus文件

我不知道为什么会这样,但是当试图使用: babel-node src/server.js 要么 nodemon –exec babel-node –stage 0 –ignore='/node_modules/' –watch src/server.js — src/server.js 我收到一个错误: SyntaxError: …/src/components/App/App.styl: Unexpected token (10:11) 9 | html 10 | min-width: 767px; min-height: 100%; height: 100%; 这似乎是因为它试图转换手写笔文件? 但我不知道为什么。 该文件包含在App.js中,如下所示: import styles from './App.styl'; 我以为它会忽略一个非.js / .jsx扩展名的文件? 当我使用webpack它完美编译server.js(我有stylus-loader),我可以从输出节点server.js,所以生产方面是好的,我只是希望直接与babel运行server.js开发。

巴贝尔有import声明的麻烦

我有一个项目,我正在使用ES6中的节点在使用babel节点运行。 现在我试图以更多的生产方式来实施babel,并尝试了两次尝试。 带有以下configuration的Webpack babel-loader: module.exports = { entry: './src/cloud/main.js', devtool: 'source-map', output: { path: './src/static/build', filename: 'bundle.js' }, module: { loaders: [ { test: /\.js$/, exclude: /node_modules/, loaders: [ 'babel-loader?presets[]=es2015', ], }, { test: /\.css$/, loaders: [ 'style-loader', 'css-loader', ], }, { test: /\.html$/, loaders: [ 'raw-loader', ], }, ], }, } 它开始抱怨在main.js中的import语句,并沉默它我用?presets[]=es2015 ,我发现在一个类似的问题。 然后,问题到达,在这个问题中,它被过滤到去往node_modules的导入语句,并带有以下消息: […]

babel-node无法find模块 – 将预设选项解释为文件名?

我打电话给这个命令: $ babel-node –presets react,es2015 server.js 但不是运行节点和使用Babel的反应和es2015预设,我得到这个错误: Cannot find module 'C:\websites\rgrjs\react,es2015' at Function.Module._resolveFilename (module.js:326:15) at Function.Module._load (module.js:277:25) at Function.Module.runMain (module.js:430:10) at Object.<anonymous> (C:\Users\Tom\AppData\Roaming\npm\node_modules\babel\lib\_babel-node.js:144:25) at Module._compile (module.js:398:26) at Object.Module._extensions..js (module.js:405:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:430:10) at startup (node.js:141:18) 这似乎表明,节点解释的react,es2015参数作为一个文件,而不是参数预设选项? 我该如何解决这个问题? babel-node的Babel文档似乎使用与上面相同的语法? 我已经尝试添加–文件名称之前,但没有帮助。 我对React和Node非常陌生,目前正在通过一门课程,所以如果这是一件非常明显的事情,我很抱歉。 这些是我的package.json文件中的依赖关系: "dependencies": { "babel": "^6.3.26", "babel-cli": "^6.4.0", "babel-core": "^6.4.0", […]

Nodemon说它重新启动我的服务器,但它不

当我更改源时,使用nodemon重新启动我的node express服务器。 当我改变任何东西的时候, nodemon正确地发现了更改后的文件并宣称重新启动服务器: [nodemon] restarting due to changes… 但是,当我与服务器交互时,我仍然得到了旧的行为(直到我手动重新启动服务器)。 我通过设置envvariablesBABEL_DISABLE_CACHE=1 (工作,没有〜/ .babel.json被创build)来禁用babel的caching。 有一些其他的caching我应该禁用,以获得正确的行为? 任何想法,为什么发生这种情况? 节点:5.1.0 nodemon:1.8.1 平台:ArchLinux 更新:这可能不是caching问题。 我注意到,保存我的文件后, nodemon不会杀死subprocess; 旧的node仍在运行( nodemon应该杀死旧的进程,并开始一个新的,对不对?)手动杀死我的脚本工作没有任何问题。

使用asynchronous时使用babel意外的令牌

使用babel 6使用async / await时获取意外标记 boot.js require("babel-core/register")({ ignore: "./node_modules" }); require("babel-polyfill"); asyncAwaitSample.js async function() { await someAsyncAction(); }() .babelrc { "presets": ["es2015", "stage-0", "react"] } 并且编译器在stringasync function() { ,它表示“意外的令牌”{“”

Webpack CLI忽略.babelrc

我正在尝试使用wepback cli来构build一个非常简单的脚本…非常多: import 'somelib'; import '../mylib'; 我在跑 webpack –output-filename index.js foo.js 但是这给了我: 错误在./foo.js中 模块parsing失败:/dir/foo.js第1行:意外的令牌 你可能需要一个合适的加载器来处理这个文件types。 | 导入'somelib'; | 导入'../mylib'; | 这表明webpack没有正确地预处理这些文件,但是我在同一个目录下有一个.babelrc文件: { "presets": ["es2015", "stage-0"], "plugins": ["transform-runtime", "transform-regenerator", "syntax-async-functions", "transform-async-to-generator"] } 我确实已经安装了相应的babel预设和插件,事实上babel在foo.js上可以正常工作。 我为Babel和Webpackfind的文档似乎都会说它会自动使用.babelrc而且我没有看到任何webpack的cli标志 ,可以让你指定babelconfiguration,包括插件/预设。 有没有什么办法可以让webpack cli使用我在.babelrc指定的插件和预设?

修复这个未定义?

我的app.js是用es6标准编写的,我的问题是>如何使用这样的代码? $('img').each(() => { var title = $(this).attr('src'); titles.push(title); }); 我观察到节点编译这个代码: 'use strict'; $('img').each(function () { var title = $(undefined).attr('src'); titles.push(title); }); 编译“这个”到“未定义”,我该如何解决这个问题? thx提前;)

Gulp和Babel:错误:找不到模块

我有一个项目,我已经build立了使用大gulp和babel 。 一切工作正常,除了当我创build一个模块,并导入它从ES6转换到ES6它不起作用。 我收到一个错误: Error: Cannot find module 'hello.js' at Function.Module._resolveFilename (module.js:440:15) at Function.Module._load (module.js:388:25) at Module.require (module.js:468:17) 这是我的gulpfile.babel.js : import gulp from "gulp"; import babel from "gulp-babel" import concat from "gulp-concat" const dirs = { src: "src", dest: "build" } gulp.task("build", () => { return gulp.src(dirs.src + "/**/*.js") .pipe(babel()) .pipe(concat("build.js")) .pipe(gulp.dest(dirs.dest)) }); gulp.task("default", ["build"]); […]

Express 4的asynchronous包装函数不会捕获错误

我试着从strongloop这个技巧https://strongloop.com/strongblog/async-error-handling-expressjs-es7-promises-generators/有一个asynchronous路由包装function,但错误的function从来没有被调用。 我也尝试把错误函数放在authRouter文件中。 在authRouter.js中: let wrap = fn => (…args) => fn(…args).catch(args[2]); router.post('/login', wrap(async (req,res) => { if (!req.body.email || !req.body.password) throw new Errors.BadRequestError(); })); export default router; 并在app.js app.use('/auth', authRouter); app.use(function(err, req, res) { console.log('in here'); const status = err.status || 500; if (status === 500) console.log(err); res.status(status); res.send({ message: err.message, error: err }); });

我必须在Node.js中使用Babel吗?

我知道Node.js现在完全支持ES6(使用nodejs 7.2.1)。 有人告诉我,Node.js的ES6实现不是生产准备好的,我必须有Babel才能生产ES6。 我读了babeljs.io,它是一个不支持ES6的老浏览器的JavaScript编译器。 我有点困惑。 Node.js是否需要Babel编译成ES5? 或者我可以使用ES6与Node.js? 生产准备好了吗? 我真的需要Babel和Node.js吗?