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

Unable to resolve module child_process #557

Closed
Arsh1a opened this issue Jul 30, 2021 · 2 comments
Closed

Unable to resolve module child_process #557

Arsh1a opened this issue Jul 30, 2021 · 2 comments

Comments

@Arsh1a
Copy link

Arsh1a commented Jul 30, 2021

When using Tesseract.js in my react-native app, I get the following error:


Unable to resolve module child_process from C:\Projects\ocr-app\node_modules\tesseract.js\src\worker\node\spawnWorker.js: child_process could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
> 1 | const { fork } = require('child_process');
      |                           ^
   2 |
   3 | let debugPort = 9229;
   4 |

I use Tesseract like this:

import React, { useState, useEffect } from "react";
import { Button, Image, View, Platform, Text } from "react-native";
import * as ImagePicker from "expo-image-picker";
import Tesseract from "tesseract.js";

export default function ImagePickerExample() {
  const [image, setImage] = useState(null);
  const [text, setText] = useState("");

  useEffect(() => {
    (async () => {
      if (Platform.OS !== "web") {
        const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync();
        if (status !== "granted") {
          alert("Sorry, we need camera roll permissions to make this work!");
        }
      }
    })();
  }, []);

  const pickImage = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.All,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
    });

    console.log(result);

    if (!result.cancelled) {
      setImage(result.uri);
      Tesseract.recognize(result.uri, "eng", { logger: (m) => console.log(m) }).then(
        ({ data: { text } }) => {
          setText(text);
        }
      );
    }
  };

  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Button title="Pick an image from camera roll" onPress={pickImage} />
      {image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
      {text && <Text>{text}</Text>}
    </View>
  );
}
@digitalbore
Copy link

Hi @Arsh1a I have the same problem.
Did you resolve that?

@Balearica
Copy link
Member

Closing this issue as the master branch now uses worker_threads rather than child_process (per #630). Therefore, you should not encounter this particular error again. If you encounter a new error, feel free to open a new 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

3 participants