将Webpack与babel和babel-preset-react和babel-preset-es2015一起使用 [英] Using webpack with babel and babel-preset-react and babel-preset-es2015

查看:198
本文介绍了将Webpack与babel和babel-preset-react和babel-preset-es2015一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试反编译我的react/es6代码,并且来自browserify.由于新的babel 6版本以及现在的大多数教程已经过时的事实,我正在努力创建一个webpack构建. 这适用于我的.babelrc:

I'm trying to transcompile my react/es6 code and am coming from browserify. I'm struggling to create a webpack build because of the new babel 6 release and the fact that most of the tutorials out there are now outdated. This works in my .babelrc:

{
  "presets": ["react"]
}

但是当我将其更改为此:

But when I change it to this:

{
  "presets": ["es2015", "react"]
}

它引发了这个神秘的错误: ERROR in ./client/App.js Module build failed: Error: You gave us a visitor for the node type "NumericLiteral" but it's not a valid type

it throws this cryptic error: ERROR in ./client/App.js Module build failed: Error: You gave us a visitor for the node type "NumericLiteral" but it's not a valid type

如果有帮助的话,这就是我的webpack.config.js:

This is my webpack.config.js if that helps at all:

module.exports = {
  entry: "./client/App.js",
  output: {
    filename: "public/bundle.js"
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel'
      }
   ]
  }
};

我明显缺少什么吗?我还交换了预设的顺序,似乎没有什么不同.我的节点模块中有babel-core,babel-loader,babel-preset-es2015,babel-preset-react和webpack.

Is there something obvious I'm missing? I've also swapped the order of the presets and it doesn't seem to make a difference. I have babel-core, babel-loader, babel-preset-es2015, babel-preset-react and webpack in my node modules.

推荐答案

我遇到了同样的问题,在我删除了node_modules目录并重新安装了所有依赖项之后,它似乎已经消失了.

I've had the same issue and it seems to have gone away after I removed the node_modules directory and reinstalled all the dependencies.

这篇关于将Webpack与babel和babel-preset-react和babel-preset-es2015一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆