How to install flow type correctly for react native#0.46+? - react-native

I've googled many sites but cannot found a tutorial that actually works for react-native + flow type.
There was flow installation guide from react-native#0.22 document, but it's gone in react-native#0.46.
However, it comes up again in Running Tests and Contributing, I tested to run npm run flow but not working, and yet it doesn't say how to make it works. It's possibly been a missing part inside of react-native documentation.
What I need is to run flow correctly with react-native. Auto-check flow every time I reload the page with ⌘R would be the best.

I just finished covering half of our project by flow and we use RN 0.44.0.
The tricky part is: do you also want to know errors inside node_modules, someone says those errors are helpful.
Anyway, I disable the error in node_modules, and here is my .flowconfig:
[ignore]
<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/flowLibs.js
.....
[include]
[libs]
./flowLibs.js
.....
[lints]
[options]
You should install flow first if you not setup correctly,
npm install --save-dev flow-bin
and also run this in you project root after install:
npm run flow init
If npm run flow init does not work, just add "flow": "flow" in npm scripts.
After init, put my .flowconfig in your project .flowconfig file.
Then create a js file flowLibs.js and if npm run flow check cause your any error like Module_Name. Required module not found
Write down code in flowLibs.js:
declare module 'Module_Name' { declare var exports: any; };
After that, you should be good to go with you project now.
BTW, don't forget add //#flow on the top of the file which you want to check type.

I found flowtype is built in with react-native#0.46+.
For react-native document, I think they should at least tell flowtype is already built in. And for the rest document ex: Testing Your Changes#flow, it won't work without flow-bin, they should mention that too.
To make flowtype of best use, I use it with Visual Studio Code.
Steps:
Install flow-bin globally, by npm i flow-bin -g.
Make sure your terminal is responsive to command flow.
Install vscode flow extension.
Set vscode workspace preference with "javascript.validate.enable": false, to disable default javascript validation, so flow validation can take place.
To access vscode preference, ALT+F,P,S for windows, ⌘+, for mac.
then you have flowtype installed with visual result with every key stroke:

Try this one:
Adding Flow to React Native
https://medium.com/react-native-training/getting-started-with-react-native-and-flow-d40f55746809
Hope this helps!

Related

How to debug neovim lsp custom command

I am attempting to get the volar vue language server to work in place of vetur for neovim's native lsp.
Using both lspconfig and lspinstall I was able to create a working custom install for sumneko_lua (unrelated but had to manually build due to some issues with the built-in :LspInstall lua). Below is that code duplicated and modified for an attempt at using this new vue server:
local vue_config = require'lspinstall/util'.extract_config('vuels')
vue_config.default_config.cmd = {'node', './node_modules/vscode-vue-languageservice/out/index.js', '--stdio'}
require'lspinstall/servers'.newvue = vim.tbl_extend('error', vue_config, {
install_script = [[
! test -f package.json && npm init -y --scope=lspinstall || true
npm install vscode-vue-languageservice#latest
]],
uninstall_script = nil
})
Running :LspInstall newvue installs properly, however :LspInfo shows this language server is attached to the buffer (of a .vue file) but not active. I believe the issue is with this path: ./node_modules/vscode-vue-languageservice/out/index.js. It exists, but may not be the correct entry point? The default vue ls simply has vls as the command because it provides a binary. Am I missing something in this package? I have yet to come across another language server without a single binary to pick out.
Thanks!
Can you try an absolute path to the out.js file? In my pretty elaborate config for a custom Volar install I'm using something just /home/myuser/dev/volar/packages/server/out/index.js (where the volar folder is just the whole volar cloned github repo). My full config is here
I don't think you can use relative paths like you did. I know you're assuming that the "./node_modules" means "workspace directory" but it's hard to tell in which directory nvim-lspconfig opens up those executables.
I have yet to come across another language server without a single binary to pick out.
Volar also provides a binary, it's volar-server (after running npm i -g #volar/server), it's just with a custom install (ie. alongside the real volar) you can't use it, because I assume you want to use your local install with custom code.
As for more indepth debugging/logging, you can check ~/.cache/nvim/lsp.log to see why the language server dies in detail.

Getting error "read ECONNRESET" while creating a new stenciljs project. How to fix the same?

I am trying to create a new stenciljs project using command npm init stencil. As soon as I choose a set up (whether app or component) and hit 'enter', a read ECONNRESET error is prompted.
I have tried updating the npm but nothing is working.
I expect the command prompt to show me the option where I can enter the project name after choosing a setup for my project but it throws an error, instead.
An ECONNRESET in npm means that npm is unable to connect to an URL where it's looking for dependencies or resources. In most cases, that means that your npm is unable to connect to the NPM Registry. But in your case it seems different.
You're trying to create a Stencil app, with npm init stencil. Under the hood, that That means you're using npm to download the create-stencil package and run it to generate the scaffold of your Stencil app.
The first part, getting the create-stencil package works well, the problem arrives while running the package. If I am correct, create-stencil tries to clone the stencil-app-starter GitHub repository and modify it. So maybe you're behind a corporate or university proxy, blocking GitHub, or another the URLs of the create-stencil resources, maybe the connection is rather flacky, maybe GitHub was done at that moment...

Vue Material postinstall failed

So I've been working on a Vue.js project for couple times now, and I am facing a problem I've never seen before.
Trying to git pull the project on another computer, or even downloading the project as a zip file, when it's time to npm install, vue-material module fails and the whole thing cannot be run.
It goes this way, with vie-material :
vue-material#1.0.0 postinstall C:\<my_things>\node_modules\vue-material
sh build/git-hooks/install.sh
Then I see this :
/usr/bin/bash: build/git-hooks/install.sh: No such file or directory
Then the modules' tree shows in the terminal, and at the end, I can see all the errors related to vue-material, with this statement :
Tell the author that this fails on your system:
sh build/git-hooks/install.sh
By the way, I tried to crate a brand new Vue project, and tried to add vue-material inside, no problem, so it has to do with my project.
Obviously though, /usr/bin/bash does not exist, since I'm running Windows 10.
Any knowledge on npm's installing routine ? I'm out of solution to try...
Can you share your package.json file?
I had this same problem just now and found that NPM could possibly be installing the incorrect version. Where I had "^vue-material": "1.0.0-beta-7" NPM was installing version 1.0.0 instead of 1.0.0-beta-7. If you remove the ^ then it may work for you. This is where I found the answer that helped me.
https://github.com/vuematerial/vue-material/issues/1155
Well, after couple times figuring out what was wrong, I got this :
I tried to use yarn and it told me that my node version was too old (vue-material needed 7.0+ and my node was 6.9, or at least that is what yarn told me), so I got myself the 8.9.3 node.
After this I tried to use yarn again, and the error with that bash script showed again.... then I just tried to use npm install again, and it worked just fine...
I don't know about the bash script thing, but one thing to remember is to always check for node and npm's version when errors happend.... (and yarn looks very cool and simple imo ^^).
You kinda made me think about a version problem though, I got you that ! :D
Problem solved....

flowtype errors in base AwesomeProject

I recently wanted to reset a react-native project to most recent version, and so I initialised the seed project - "AwesomeProject"... The problem is that it comes with 19 flowtype errors "out of the box"
node_modules/react-native/Libraries/CustomComponents/NavigationExperimental/NavigationCardStackStyleInterpolator.js
lines:91,94,97,104,107,137,142,148
node_modules/react-native/Libraries/CustomComponents/NavigationExperimental/NavigationHeaderStyleInterpolator.js
lines:57,68,74,87,94
node_modules/react-native/Libraries/Experimental/WindowedListView.js
lines:629, 629, 665,665
node_modules/react-native/Libraries/Image/Image.ios.js
line:272
I am reluctant to make changes to these files as it may create knock on effects. Does anyone have a work around?
In general, whenever you want flow to ignore a file, you can just specify that file under the [ignore] section of your .flowconfig.
That said, I just react-native init'd a project, using react-native-cli 1.0.0 and react-native 0.29.1, and ran a flow server on the root of my project, and didn't get any errors.

react-native init hangs/stalls with no error

New to react, working through a udemy tutorial on a Mac. Installed node ok but when I go to start a project
react-native init projectname
terminal output:
This will walk you through creating a new React Native project in /Users/myuserid/projects/projectname
Installing react-native package from npm...
and it just "hangs" there... seemingly frozen or chugging along. When I check Monitor it looks like Terminal is using 0% CPU. There is no indication (backslash flipping or otherwise) that it is processing.
Inside the projectname directory is a "package.json" file and a "node_modules" file with a bunch of subfiles.
I saw this post with a similar problem (https://github.com/facebook/react-native/issues/2806), but doesn't look like there is a remedy. Is there any way to speed this up? How can I tell if it has stalled forever? Will this happen during every project init I do?
I'm not in China... I have fast internet... and I'm using NPM 3.3.12
Thank you!
I got the same issue , and i found the 1st comment on the question is useful .
Indeed , If no error, it means that it takes time to download dependencies.
You can track downloading by adding --verbose :
react-native init projectname --verbose
You will spend a long period to reach 50% of downloading.
Nevertheless, you might face the following error :
npm WARN react-native#0.34.0 requires a peer of react#~15.3.1 but none
was installed. npm verb exit [ 0, true ]
If so , check this thread .
I had the same problem while using an existing (empty) directory as App name
It worked as soon as I changed the App name to something new