speedskater / babel-plugin-rewire

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

babel/plugin-transform-typescript and rewire #229

Open Ranjeet-Naidu opened 4 years ago

Ranjeet-Naidu commented 4 years ago

Hi guys the babel plugin rewire doesn't seem to work with babel 7. Has this issue been previously raised?

"@babel/core": "^7.7.4", "babel-plugin-rewire": "^1.2.0"

In karma config

{
  test: /\.(js|jsx|ts|tsx)$/,
  exclude: [/app\/lib/, /node_modules/],
  use: [
    {
      loader: 'babel-loader',
      options: {
        presets: ['@babel/preset-env'],
        plugins: ['rewire']
      }
    }
  ]
}

This problem is likely caused by another plugin injecting "_RewireAPI__" without registering it in the scope tracker. If you are the author of that plugin, please use "scope.registerDeclaration(declarationPath)". The exported identifier "_RewireAPI__" is not declared in Babel's scope tracker as a JavaScript value binding, and "@babel/plugin-transform-typescript" never encountered it as a TypeScript type declaration. It will be treated as a JavaScript value.

TranquilMarmot commented 4 years ago

This has been driving us crazy and we'd love to see a fix for it! It does seem like this project is dead, though. We're working on switching to Jest and using its built-in mocks instead.