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

JSON Parse error: Unexpected character issue #17

Closed
Sly777 opened this issue Apr 18, 2024 · 2 comments
Closed

JSON Parse error: Unexpected character issue #17

Sly777 opened this issue Apr 18, 2024 · 2 comments

Comments

@Sly777
Copy link

Sly777 commented Apr 18, 2024

Hey @hans00, I'm testing your suggestions and your code example but somehow I always get JSON Parse error: Unexpected character issue on parsing downloaded model. I tried on simulator but I couldn't pass this error at all.

This is the code area on transformers.js that gives this error. (node_modules/@xenova/transformers/src/utils/hub.js)
screenshot 2024-04-18 at 14 58@2x

For polyfills, I did something like this;

import 'text-encoding-polyfill'; // support TextEncoder
import { polyfill as polyfillReadableStream } from 'react-native-polyfill-globals/src/readable-stream';
import { polyfill as polyfillFetch } from 'react-native-polyfill-globals/src/fetch';
import { Buffer } from 'buffer';
import XRegExp from 'xregexp';

polyfillReadableStream();
polyfillFetch();

global.Buffer = Buffer;

// replace default RegExp to support unicode
const nativeRegExp = global.RegExp;
const newRegExp = (...args) => {
  global.RegExp = nativeRegExp;
  const result = XRegExp(...args);
  global.RegExp = newRegExp;
  return result;
};
global.RegExp = newRegExp;

I added fetch and readable stream because it didn't work if I don't add them. Do you have any clue why I keep getting this?

package versions;

"@xenova/transformers": "^2.17.0"
"expo": "~50.0.17"
"react-native": "0.73.6"
"text-encoding-polyfill": "^0.6.7"
"xregexp": "^5.1.1"
"react-native-polyfill-globals": "^3.1.0"
"@babel/core": "^7.20.0"
"@babel/plugin-transform-export-namespace-from": "^7.24.1"
"babel-plugin-transform-import-meta": "^2.2.1",

babel config

module.exports = (api) => {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: [
      '@babel/plugin-transform-export-namespace-from',
      'babel-plugin-transform-import-meta',
    ],
  };
};
@hans00
Copy link
Owner

hans00 commented Apr 19, 2024

"@xenova/transformers": "^2.17.0"
It looks you installed the wrong version of transformers.
The PR of RN support have not merged.
So that you should install from source or pre-release

@Sly777
Copy link
Author

Sly777 commented Apr 19, 2024

Thanks a lot for your help, @hans00! I will try my code with your pr changes.

@hans00 hans00 closed this as completed May 4, 2024
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

2 participants