最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using webpack with babel and babel-preset-react and babel-preset-es2015 - Stack Overflow

programmeradmin1浏览0评论

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"]
}

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

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'
      }
   ]
  }
};

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.

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"]
}

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

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'
      }
   ]
  }
};

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.

Share Improve this question edited Nov 11, 2015 at 19:28 hiro protagonist 46.9k17 gold badges92 silver badges117 bronze badges asked Nov 3, 2015 at 19:24 syu15syu15 2713 silver badges12 bronze badges 1
  • Have you seen the troubleshoot section of the github repo? – Rik Commented Nov 3, 2015 at 21:19
Add a comment  | 

4 Answers 4

Reset to default 14

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.

I would start here if I were you. This will give you a very minimal template for React where you can reverse engineer and start learning how to use React inside of a webpack build. React Boilerplate This is very useful for getting started quick and easily, while learning webpack for what you will make use of it. I have always found the webpack documentation hard to figure out for what I need. I hope this helps.

I solved this probleum by nvm even though i reinstalled by npm serveral times useless. I changed node version to 5+ then it will goes well althogh I already in 5+ node environment. that's imagine.

I had the same issue. It turned out that I was adding a prototype method to the class "Object" that already exist.

发布评论

评论列表(0)

  1. 暂无评论