Open naishe opened 3 years ago
Hi 👋
Any updates on TypeScript support @naishe @speedskater ? Couldn't get this to run with TypeScript neither, I'm getting:
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.
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)".
You can see the setup here (it's very minimal, 2 webpack loaders and 2 babel plugins): https://github.com/stefanpl/nodejs-typescript-starter/tree/install-babel-plugin-rewire
I also tried this repo, but it's archived and doesn't work for me neither.
Any input very much appreciated!
@stefanpl -- I got it working for the client back then. It was not as convoluted. I need to go back and check how. If you can wait until early next week, I'd probably be able to prepare a PoC/
@naishe I would very much appreciate it! I can definitely wait until then, just at some point it would be nice to have it for proper testing in a TS environment.
@naishe Sorry, any chance you could write a quick guide on how to do it?
Same question here. It does not seems to prevent to work with TS though but is an ugly error everytime I run the testing tools.
I am trying to setup a new Typescript project with Mocha, and Chai. One of the unit tests require me to use
rewire
, which does not work with ES6 imports. So, I ended up usingbabel-plugin-rewire
. But, I can't get it to work. For example, the following line:Fails with
TypeError: _get__(...).__get__ is not a function
.I have setup a minimalistic reproducible public repo here: https://github.com/naishe/typescript-babel if you want to play with it.
Here is the minimal project setup:
src/hello.ts
test/index.spec.ts
test/babel-register.js
babelrc.json
babel.config.js
mocharc.json
Relevant part of package.json
npm test
emmits this:Relevant StackOverflow entry: https://stackoverflow.com/questions/65725761/babel-plugin-rewire-does-not-work-in-a-typescript-project