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

Worker Script Path has 'http:/localhost' prepended, causing MODULE_NOT_FOUND error #474

Closed
sssanwar opened this issue Aug 4, 2020 · 6 comments

Comments

@sssanwar
Copy link

sssanwar commented Aug 4, 2020

Describe the bug
When trying to run tesseract.js in Jest for a unit test I get this error message saying it's unable to load worker-script. Upon inspection the supplied path appeared somehow has been concatenated with 'http:/localhost/'.

Error: Cannot find module '**/Users/myusername/Projects/my-app/http:/localhost/Users/myusername/Projects/my-app/node_modules/tesseract.js/src/worker-script/node/index.js**'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

To Reproduce
Install tesseract.js and tesserract-core.js throught npm or yarn. I am using yarn in this case. Write a unit test in jest to load tesseract. I tried supplying the 'workerPath', it didn't seem to help. The supplied path would also have the 'localhost' string prepended to the path.

The issue does not happen when I run tesseract.js in a browser.

Expected behavior
The worker-script path shouldn't have been concatenated with 'http:/localhost'.

Desktop:

  • OS: MacOS 10.15.6
  • Node: v12.16.2
  • Tesseract.js: 2.1.1
@MaffooBristol
Copy link

MaffooBristol commented Aug 10, 2020

Same issue here on Node 14

Also does it on tesseract.js@next

@slonoed
Copy link

slonoed commented Oct 16, 2020

Hi @sssanwar !
Did you find workaround for it?

@marcincichocki
Copy link

This is strictly jest "issue". The error origins here because tesseract tries to detect current environment by simple check typeof window === 'object'. Unfortunately jest loads jsdom by default which sets global window variable. Therefore tesseract tries to load dependencies via http.

To solve it simply set testEnvironment option to node in jest config. If you somehow rely on jsdom in your tests I suggest using:

/**
 * @jest-environment node
 */

at the top of the affected file.

related issue: jestjs/jest#3692

@Balearica
Copy link
Collaborator

If this issue is still active can somebody please upload a reproducible code snippet/repo that produces this error? Seems likely this can be fixed but I'm not a Jest user.

@marcincichocki
Copy link

@Balearica I believe this was fixed(#498) and deployed in 2.1.5.

@Balearica
Copy link
Collaborator

@marcincichocki Thanks for confirming, closing the issue.

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