-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReferenceError: Can't find variable: TextDecoder #167
Comments
Try following the directions here. It's not enough to require @cto.af/textdecoder, you have to get it hooked into the correct global variable where it's supposed to be. |
Thanks for the quick reply! I followed the instructions (added the package and modified the metro.config.js). Now I am getting another Error:
Thanks again for your help! |
Can you give me the full backtrace please? Feel free to trim out path names that are local to your environment. |
Sure, here are the errors I am getting. I don't see anything related to
I did a try catch block around the require like:
and getting.
|
I assume that when you remove the |
That's correct. :) But I want to use it. :) |
OK, I just did this on my local box, and everything worked:
module.exports = {
resolver: {
extraNodeModules: {
stream: require.resolve('stream-browserify'),
},
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
};
// require() also worked
import prereqs from 'cbor-rn-prereqs';
import cbor from 'cbor';
// somewhere down below in the view
{cbor.encode(254).toString('hex')}
{cbor.decode('18ff')}
What I saw in the iOS emulator, in the right spot: |
Thanks a lot. I already read the posts. I am still getting:
The only difference I see is that I am using an expo typescript app. |
Try this, which just worked for me in an expo/TypeScript project: const p = require('cbor-rn-prereqs');
p.patchGlobal(globalThis);
const cbor = require('cbor'); I think the difference is that |
I haven't been able to cause the TypeError you're getting, and now it seems like this works (although I'd swear it didn't the first time I tried it): require('cbor-rn-prereqs');
const cbor = require('cbor'); Why don't you email me at the address in the package.json file, and we'll see if we can either set up a time to do a screen share, or get me access to your project. |
Thanks a lot but I am trying some things and report back. Sure, if I have still no success, I post a public repo link. |
Ok, I found the problem.
in my I replaced Do you know something that could prevent |
At this point, I think we're pretty clear it's an issue with metro/react-native, in which I have almost no expertise, sorry. However, let me suggest some avenues of exploration:
|
Can you send the full contents of your |
Sorry for not getting back to you sooner.
Thanks for your help! |
Contents of |
In my case, this was problem with documentation. While documentation states, that node 10+ versions are supported, node v10 does not have TextDecoder class (which was added in later versions). |
I see I missed at least one document reference to the move to Node 12 in the last major release. WillFix, sorry. Also see #169, where I chased this down for a different flavor of NativeScript. The conclusion there is that NativeScript added a broken TextDecoder implementation. |
I fixed the doc issue (note that we're up to requiring Node 14 now). I think this is as solved as it's going to get until NativeScript fixes their TextDecoder bug. |
Hello, thanks for your work!
I try to use this library in a react-native (expo) app and got a problem getting it working.
I read here #162 that it should work if i use the
Simple TextDecoder polyfill
but i am still gettingReferenceError: Can't find variable: TextDecoder
.Any ideas?
The text was updated successfully, but these errors were encountered: