Webpack 2 - 无法在字符串上创建属性“映射" [英] Webpack 2 - Cannot create property 'mappings' on string

查看:29
本文介绍了Webpack 2 - 无法在字符串上创建属性“映射"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从有效的 Webpack v1 配置迁移到 Webpack 2.但在尝试运行构建时遇到错误:

Migrating from a working Webpack v1 config to Webpack 2. But running into an error while trying to run the build:

 ERROR in ./src/index.jsx
 Module build failed: TypeError: /home/pierce/Projects/my-js-app/src/index.jsx: Cannot create property 'mappings' on string 

我已更新我的加载程序以匹配新格式:

I have updated my loaders to match the new format:

module: {
  rules: [
    {
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
      loader: "babel-loader"
    },
    {
      test: /\.(jpg|png)$/,
      loader: 'file-loader',
      query: {
        name: '[path][name].[hash].[ext]',
      },
    },
    { 
      test: /\.css$/, 
      loader: "style-loader!css-loader" 
    },
    {
      test: /\.scss$/,
      use: [
        { 
          loader: 'style-loader' 
        },
        { 
          loader: 'css-loader'
        }, 
        { 
          loader: 'sass-loader',
          options: { sourceMap: true } 
        }
      ]
    },
    {
      test: /\.(woff|woff2|eot|ttf|svg)(\?v=\d+\.\d+\.\d+)?/, 
      loader: 'url-loader',
      query: { 
        limit: 100000
      }
    },
    { 
      test: /\.icon-svg$/, 
      use: [{loader:'babel-loader'}, {loader: 'svg-react-loader'}] 
    },
    // Bootstrap 3
    { 
      test: /bootstrap-sass\/assets\/javascripts\//, 
      loader: 'imports-loader?jQuery=jquery' 
    }
  ]
},

就好像某些东西没有像以前那样编译,因此导致了 TypeError.

It's as if something is not being compiled the way it was before, therefore causing a TypeError.

推荐答案

原来我是 babelifing 两次.

Turns out I was babelifing twice.

如果您还将 webpack.config.js 拆分为不同环境的单独文件,请确保 webpack.dev.config.js 不包含一个 babel-loader 条目,如果你的 webpack.base.config.js 有的话.

If you're also splitting your webpack.config.js into separate files for your different environments, be sure that webpack.dev.config.js does not include a babel-loader entry if your webpack.base.config.js does.

否则,如果您第二次使用加载器两次将导致错误.这不是 Webpack 2 错误,而是 webpack splitting-configs-and-missing-a-small-thing 错误

Otherwise, if you use the loader twice the 2nd time around will cause an error. This wasn't a Webpack 2 error but a webpack splitting-configs-and-missing-a-small-thing error

这篇关于Webpack 2 - 无法在字符串上创建属性“映射"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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