I port some packages on Node to React Native using ReactNativify (instead of the more "hacky" rn-nodeify ) for the browser / shim Node API object in the dependency tree. I am developing in VSCode.
With ReactNativify, you use babel-plugin-rewrite-require in .babelrc (or using javascript in rn-cli.config.js + transformer.js ):
{ ... "plugins": [ ["rewrite-require", { "aliases": { "constants": "constants-browserify", "crypto": "react-native-crypto", "dns": "node-libs-browser/mock/dns", "domain": "domain-browser", "stream": "stream-browserify", "_stream_duplex": "readable-stream/duplex", "_stream_passthrough": "readable-stream/passthrough", "_stream_readable": "readable-stream/readable", "_stream_transform": "readable-stream/transform", "_stream_writable": "readable-stream/writable", ... etcetera } }] ... }
(see full example here )
This works pretty well, and I get beautiful code completion / IntelliSense in VSCode, etc.
Now I want to use Node Stream in MyStream.js like this:
import { Duplex } from 'stream' class MyStream extends Duplex {
For the first time, it seemed to work. I got code completion, the ability to "Go to type definition". Everything was fine.
I like the type of security and "intellisense-to-the-max", so I decided to convert the project / code to typescript. There are no problems.
But when changing MyStream.js to MyStream.ts IDE complained that no packet stream was found.
I tried different things without success, then decided to convert back to javascript, but now the original workflow did not find the code anymore. Returning to Typescript, now there is no error checking at all. In short, it all feels very hacked and unstable.
My questions:
- Does anyone have any examples of using Node 'stream' with React Native?
- Are there any special considerations for the correct operation of code in VSCode (as with regular ES6 + Typescript)?
- Is it possible to use ReactNativify or rn-nodeify in Typescript in the same way as with regular js?
[Update: one thing resolved. Restarting VSCode will re-verify the code]