How to use a Node stream with (or without) Typescript in React Native and VSCode

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 { // ... implementation } 

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]

+1
javascript typescript visual-studio-code browserify
Jul 29 '17 at 9:46 on
source share

No one has answered this question yet.

See similar questions:

31
How to run my node.js project on Android?
fourteen
Viable Opportunities to Launch NodeJS on Android (August 2017)

or similar:

586
What is the difference between React Native and React?
2
Typewriting and Reduction Required
2
vscode react-native: launchReactNative.js
2
Is it possible to run Node fs.readFileSync () in React Native?
one
Howto patch / shim crypto.getRandomValues ​​for React Native
0
TypScript + select2 + browserify = TypeError: $ (...). Select2 is not a function
0
Typing and Node.JS merged
0
Failed to connect to the development server. Verify the following: - The host server is up and running on the same network.
-one
500 (Internal Server Error) converts a node request to a fetch request
-one
How VSCode Handles Conflicting Intellisense Hover Extensions



All Articles