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

ReferenceError with TextEncoder #143

Open
fangzhou-xie opened this issue Jun 16, 2022 · 5 comments
Open

ReferenceError with TextEncoder #143

fangzhou-xie opened this issue Jun 16, 2022 · 5 comments

Comments

@fangzhou-xie
Copy link

Thanks for the package for bridging JS into R! I was reading JavaScript for R, Chapter 18 and was thinking if I can browserify jsdom to be used in R.

I have in.js:

global.jsdom = require('jsdom');

converted by:

browserify in.js -o jsdom.js

and then called in R:

library(V8)
jsdom <- v8()
jsdom$source("node/jsdom.js")

But then I got an error ReferenceError: TextEncoder is not defined.

My searching on Google told me that it could be Node version problem (using Node 18 first, but noticed V8 engine version 9.6.180.12 and then tried Node 16). But downgrading didn't work. I also tried to hack in whatwg-url source code, but then I got TypeError: util.TextEncoder is not a constructor error.

I am not sure why this is the case (sorry for my not being very proficient in JS), but jsdom should work fine with browserify and I think this translation should work out. And potentially I can call jsdom from R via V8.

Any help/insight will be appreciated! Thank!

@mahideel
Copy link

Hi , have you managed to solve your issue? I have the same problem, all the function I tried calling came up with ReferenceError: Function is not defined.

Function - whichever function I tried calling.

Thanks.

@fangzhou-xie
Copy link
Author

Unfortunately no. I am not very familiar with JS and I only tried this because it seems straightforward. But maybe it is not as easy as it seems to be.

@jeroen
Copy link
Owner

jeroen commented Nov 28, 2022

You are probably trying to use functions which are not part of core JavaScript. See this vignette: https://cran.r-project.org/web/packages/V8/vignettes/npm.html

@mahideel
Copy link

mahideel commented Nov 28, 2022 via email

@nanxstats
Copy link

I used the hints here and saved text-encoding explicitly as another dependency. Doing this will eliminate the error "ReferenceError: TextEncoder is not defined" when sourcing jsdom.js. See my blog post for details: https://nanx.me/blog/post/r-readability-parser/

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

4 participants