I'm trying to use NDEFReader() for NFC scan/write in React.
This feature works from Chrome 81 (you can try it on your mobile in Chrome beta today on links below).
GoogleChromeNfcSample, WhatWebCanDoTodayNfc
To enable this feature, you need to go into chrome://flags/ and enable Experimental Web Platform features.
The problem is that I can't make this work in React. I use create-react-app with TypeScript and console output:
Cannot find name 'NDEFReader'
I think that this causes a webpack check. I already tried change some settings in tsconfig.json but nothing worked. Does anyone know, how to enable experimental js/ts compilation, to enable this feature?
This isn't about Webpack checks or your tsconfig, or "experimental JavaScript".
It's just that there are no types for
NDEFReader()available, so TypeScript thinks you have a typo.You can stub in a type for
NDEFReaderwith a file likeextra-globals.d.ts(the name doesn't matter so long as it's a.d.ts) in your source tree. This basically tells TypeScript that the global Window interface has one extra field,NDEFReader, whose type you don't really know: