speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
843 stars 90 forks source link

^1.1.1 fails to transpile with webpack ^3.5.4 #202

Open Steffan-Ennis opened 6 years ago

Steffan-Ennis commented 6 years ago

Fails to tranpile with webpack 2 and Karma.

karma@1.7.0 , webpack@3.5.4, babel-rewire-plugin@1.1.0

Property local of ImportDefaultSpecifier expected node to be of a type ["Identifier"] but instead got "CallExpression" error on all imported modules

karma.config.js

....
module  : {
        noParse : [
          /\/sinon\.js/
        ],
        rules : webpackConfig.module.rules.concat([
          {
            test   : /sinon(\\|\/)pkg(\\|\/)sinon\.js/,
            loader : 'imports-loader?define=>false,require=>false'
          },
          {
            test    : /\.(js|jsx)$/,
            exclude : [
              /node_modules/,
              /lib/
            ],
            loader  : 'babel-loader',
            options: {
              presets: ['es2015', 'stage-0', 'react', 'airbnb'],
              plugins : [
                'rewire',
                'transform-runtime',
                'transform-decorators-legacy',
              ],
            }
          },
          {
            test    : /\.(js|jsx)$/,
            include: [/lib/],
            exclude: [/node_modules/],
            loader  : 'babel-loader',
            options: {
              presets: ['es2015', 'stage-0', 'react'],
              plugins : [
                'rewire',
                'istanbul',
                'transform-runtime',
                'transform-decorators-legacy',
              ],
            }
          },
        ])
      },
...

Rolling back to 1.0.0-rc-4 seems to work

cuijing1031 commented 6 years ago

I got the same error message. It was because i uesd babel-transform-imports which will change the ImportSeicifier to the importDefaultSpecifier. When i removed babel-transform-imports , it worked well again.