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

fork is not a function #110

Closed
madc0w opened this issue Feb 23, 2017 · 6 comments
Closed

fork is not a function #110

madc0w opened this issue Feb 23, 2017 · 6 comments

Comments

@madc0w
Copy link

madc0w commented Feb 23, 2017

I've tried with npm installation, with a <script> tag as described, and also by downloading and including the source code in a local library. Same result:

Uncaught TypeError: fork is not a function
    at Object.spawnWorker (http://localhost:3000/packages/modules.js?hash=f54899d92a94c3539fde21055ed0f94e4ddb63b7:26984:14)
    at TesseractWorker._delay (http://localhost:3000/packages/modules.js?hash=f54899d92a94c3539fde21055ed0f94e4ddb63b7:26925:42)
    at TesseractWorker.recognize (http://localhost:3000/packages/modules.js?hash=f54899d92a94c3539fde21055ed0f94e4ddb63b7:26901:15)
    at eval (eval at evaluate (:85:21), <anonymous>:1:11)
    at Object.added (http://localhost:3000/app/app.js?hash=0f20b482913432cbce12028cd756067146dfbc96:11275:8)
    at http://localhost:3000/packages/minimongo.js?hash=66cc6ab213289f154f49d61566dba8ff9dfc33b2:410:13
    at Meteor._SynchronousQueue.runTask (http://localhost:3000/packages/meteor.js?hash=e3f53db3be730057fed1a5f709ecd5fc7cae1229:721:11)
    at Meteor._SynchronousQueue.flush (http://localhost:3000/packages/meteor.js?hash=e3f53db3be730057fed1a5f709ecd5fc7cae1229:749:10)
    at Meteor._SynchronousQueue.drain (http://localhost:3000/packages/meteor.js?hash=e3f53db3be730057fed1a5f709ecd5fc7cae1229:757:12)
    at LocalCollection.insert (http://localhost:3000/packages/minimongo.js?hash=66cc6ab213289f154f49d61566dba8ff9dfc33b2:619:22)

Then I tried installing the fork npm package ( https://www.npmjs.com/package/fork ). This fails, since (I am guessing...) fork is a server-side function. require("fork") on the client results in "Uncaught Error: Cannot find module 'fork'". On the server, I can successfully require fork, but that does not solve this issue, as I was really hoping to use Tesseract client-side.

@madc0w
Copy link
Author

madc0w commented Feb 23, 2017

Surprisingly, including the <script> tag in a simple HTML file (no Meteor) does actually work. I can only suppose that my attempts to use tesseract.js in Meteor failed due to some mysterious Meteor dependence mangling madness.

Now... we encounter the next issue:

		Tesseract.recognize(canvas).then(function(result) {
			console.log("result " + result);
		});

The "then" function is never executed. I only see this error one time, on load:

pre-main prep time: 111 ms
worker.js:8474 Uncaught DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.
    at https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8474:16
    at Object.respond (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8706:9)
    at Object.dispatchHandlers (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8726:17)
    at https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8473:17

OK, moving on to server-side solutions...

@danrubins
Copy link

Hey @madc0w, I was having the same problem with this in Meteor. Once I saw the attempt at using child_process on the client side, I just included the script like you did. Adding a progress handler seems to fix things from that point:

Tesseract.recognize(file)
  .then(function (result) {
    console.log(result)
  }).progress(function (result) {
    console.log(result['status'] + ' (' + (result['progress'] * 100) + '%)')
  })

@antimatter15
Copy link
Member

I'm guessing what's happening is that Meteor is ignoring the package.json browser override and trying to load the nodejs server version of the code (which uses child_process.fork). This seems related to this Meteor bug

@madc0w
Copy link
Author

madc0w commented Mar 12, 2017

@dhrubins , thanks for that hint. After adding the progress handler, I now advance to the next obstacle:

loading tesseract core (0%)
grafix.js:35 loading tesseract core (100%)
grafix.js:35 initializing tesseract (0%)
index.js:10 pre-main prep time: 201 ms
grafix.js:35 initializing tesseract (100%)
worker.js:8474 Uncaught DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': An object could not be cloned.
    at https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8474:16
    at Object.respond (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8706:9)
    at Object.dispatchHandlers (https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8726:17)
    at https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/worker.js:8473:17
(anonymous) @ worker.js:8474
respond @ worker.js:8706
dispatchHandlers @ worker.js:8726
(anonymous) @ worker.js:8473

Note that this is with just plain HTML/JS, no Meteor involved here at all.

Anyway, I've long abandoned this client-side OCR approach in favor of using Tesseract on the server, which works fine.

@peonmodel
Copy link

dont know if people had figured it out
but i am able to use Tesseractjs client-side with meteor 1.5.1 by importing directly from /dist/

import Tesseract from 'tesseract.js/dist/tesseract.js';

@jeromewu
Copy link
Member

Close for now as the issue is resolved.

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