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

jschardet.min.js cannot be loaded into vm in node.js #97

Closed
bpasero opened this issue Jul 9, 2024 · 0 comments · Fixed by #96
Closed

jschardet.min.js cannot be loaded into vm in node.js #97

bpasero opened this issue Jul 9, 2024 · 0 comments · Fixed by #96

Comments

@bpasero
Copy link
Contributor

bpasero commented Jul 9, 2024

See this code:

const vm = require('vm');
const mod = require('module');
const fs = require('fs');

const content = fs.readFileSync('<path to>/jschardet.min.js', 'utf8');
const scriptSource = mod.wrap(content.replace(/^#!.*/, ''));
const script = new vm.Script(scriptSource);
const compileWrapper = script.runInThisContext({
    filename: 'jschardet.js',
    displayErrors: true
});

console.log(compileWrapper.apply(globalThis, []));

When you run it with node.js 20.x:

TypeError: Cannot read properties of undefined (reading 'iterator')
    at $jscomp.initSymbolIterator (evalmachine.<anonymous>:1:384)
    at $jscomp.makeIterator (evalmachine.<anonymous>:2:42)
    at evalmachine.<anonymous>:164:334
    at new c (evalmachine.<anonymous>:164:465)
    at evalmachine.<anonymous>:662:132
    at 42../constants (evalmachine.<anonymous>:662:395)
    at f (evalmachine.<anonymous>:5:32)
    at evalmachine.<anonymous>:5:66
    at 19../logger (evalmachine.<anonymous>:390:112)
    at f (evalmachine.<anonymous>:5:32)

Fix is in #96

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

Successfully merging a pull request may close this issue.

1 participant