Skip to content
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

utf8.decode() is not a function error #17

Closed
ghost opened this issue Jun 14, 2016 · 12 comments
Closed

utf8.decode() is not a function error #17

ghost opened this issue Jun 14, 2016 · 12 comments

Comments

@ghost
Copy link

ghost commented Jun 14, 2016

Hi,

We've followed your instructions in the repo but cannot call the decode method. Encode works fine. Any insights as to why this might happen?

Thank you

@mathiasbynens
Copy link
Owner

What have you tried exactly? What happens exactly?

@ghost
Copy link
Author

ghost commented Jun 14, 2016

We imported the package:

var utf8 = require('utf8');

then invoked the decode method on a string bytes from a base64 string (or any input) with utf8.decode(input) i get the error.

utf8.encode(input) works fine.

@mathiasbynens
Copy link
Owner

Please provide a reduced test case so I can reproduce the error.

@ghost
Copy link
Author

ghost commented Jun 14, 2016

Unhandled JS Exception: utf8.decode is not a function. (In 'utf8.decode(bytes)', 'utf8.decode' is undefined)

@mathiasbynens
Copy link
Owner

It’s hard to figure out what you’re doing exactly, unless you tell me.

It works fine for me:

$ npm i utf8

$ node -v
v6.2.1

$ node -p 'require("utf8").decode("\xE2\x99\xA5")'
♥

Since there appears to be no issue with utf8.js, I am closing this issue.

Provide a reduced test case and I’ll take a look.

@txm
Copy link

txm commented Jun 19, 2017

React Native problem? I'm getting the same error as this chap.

https://stackoverflow.com/questions/41252188/react-native-how-to-decode-base64-encoded-string

@mcmar
Copy link

mcmar commented Jun 27, 2017

@mathiasbynens the simplified test case is

react-native init DemoProj
cd DemoProj
yarn add utf8

then open index.ios.js and add the lines

import utf8 from 'utf8';
console.log(utf8);

then start the app using

react-native run-ios

then open the developer panel (⌘+D) and select "Debug JS Remotely"
That should open a panel in your web browser. Then press ⌘-⌥-i and select console to see the result of the console.log statement. You should see that encode is defined, but decode and version are not.

@mcmar
Copy link

mcmar commented Jun 27, 2017

Looks like Facebook has a utility that takes precedence over this one when you do an import or require.
https://github.com/facebook/react-native/blob/9ee815f6b52e0c2417c04e5a05e1e31df26daed2/Libraries/Utilities/utf8.js
#rude

@mcmar
Copy link

mcmar commented Jun 27, 2017

@davidaurelio Got any suggestions for what to do about this?

@mcmar
Copy link

mcmar commented Jun 27, 2017

@mathiasbynens Maybe consider also publishing this under react-native-utf8 so us plebs can have access to your awesome library? Then leave a comment in the readme for react-native folks to know what to do. Can you even publish the same library under two namespaces? Is that allowed?

@davidaurelio
Copy link

@mcmar can you send a PR for React Native to rename the internal module to something different?

@arribbar
Copy link

arribbar commented Dec 6, 2017

well, I solved this error not using this project but the old method:

decodeURIComponent(escape(s))

mathiasbynens added a commit to mathiasbynens/react-native that referenced this issue Dec 11, 2017
This makes it possible for developers to use the `utf8` package from npm in combination with React Native.

Ref. mathiasbynens/utf8.js#17
mathiasbynens added a commit to mathiasbynens/react-native that referenced this issue Dec 11, 2017
This makes it possible for developers to use the `utf8` package from npm in combination with React Native.

Ref. mathiasbynens/utf8.js#17
mathiasbynens added a commit to mathiasbynens/react-native that referenced this issue Jan 13, 2018
It was not used anyway.

Furthermore, removing it makes it possible for developers to use the `utf8` package from npm in combination with React Native.

Ref. mathiasbynens/utf8.js#17

Update __utf8.js
mathiasbynens added a commit to mathiasbynens/react-native that referenced this issue Jan 13, 2018
It was not used anyway.

Furthermore, removing it makes it possible for developers to use the `utf8` package from npm in combination with React Native.

Ref. mathiasbynens/utf8.js#17

Update __utf8.js
mathiasbynens added a commit to mathiasbynens/react-native that referenced this issue Jan 13, 2018
It was not used anyway.

Furthermore, removing it makes it possible for developers to use the `utf8` package from npm in combination with React Native.

Ref. mathiasbynens/utf8.js#17

Update __utf8.js
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Jan 20, 2018
Summary:
As requested by davidaurelio in mathiasbynens/utf8.js#17 (comment), this makes it possible for developers to use the `utf8` package from npm in combination with React Native.

Ref. mathiasbynens/utf8.js#17
Closes #17146

Differential Revision: D6765030

Pulled By: hramos

fbshipit-source-id: dda9b3255618470aea2e32c5ba3cf1325e2ec997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants