question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning of require cycle using code similar to the example

See original GitHub issue

Using the code as example, this warning always appear:

Require cycle: node_modules/vision-camera-code-scanner/src/index.ts -> node_modules/vision-camera-code-scanner/src/hook.tsx -> node_modules/vision-camera-code-scanner/src/index.ts

The code being used:

import React from "react";
import { Camera, useCameraDevices } from "react-native-vision-camera";
import { useScanBarcodes, BarcodeFormat } from "vision-camera-code-scanner";

export function CameraWrapper(props) {
    const [hasPermission, setHasPermission] = React.useState(false);

    const devices = useCameraDevices();
    const device = devices.back;

    const [frameProcessor, barcodes] = useScanBarcodes([BarcodeFormat.QR_CODE], {
        checkInverted: true
    });

    React.useEffect(() => {
        (async () => {
            const status = await Camera.requestCameraPermission();
            setHasPermission(status === "authorized");
        })();
    }, [props]);

    React.useEffect(() => {
        if (barcodes.length === 0) return;
        console.log(barcodes);
    }, [barcodes]);

    return (
        device != null &&
        hasPermission && (
            <Camera
                style={props.style}
                device={device}
                photo={true}
                audio={false}
                isActive={true}
                frameProcessor={frameProcessor}
                frameProcessorFps={props.fps || 5}
            />
        )
    );
}

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

2reactions
berseckcommented, May 9, 2022

Yes correct, this should be fixed here. What I’m suggesting is a palliative fix for your own project while the library doesn’t fix this themselves. So you don’t need to keep that warning in your project.

0reactions
anderpazcommented, Aug 24, 2022

Yes correct, this should be fixed here. What I’m suggesting is a palliative fix for your own project while the library doesn’t fix this themselves. So you don’t need to keep that warning in your project.

There is a forecast for the release of this release with the correction?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Require cycles are allowed, but can result in uninitialized ...
js This is what triggers the Require cycle warning because a module that was imported from one place, is then rendering and asking...
Read more >
The code review feature seems too expensive to run on every ...
The code review feature seems too expensive to run on every PR automatically (to me): $0.75 per 100 lines of code. From their...
Read more >
Getting Started with Victory Native
If you are building a project with native code, you will need to link the native ... Native apps (on both iOS and...
Read more >
Initialization error | Database Hub - Back4App
js Require cycles are allowed, but can result in uninitialized values. Consider refactoringto remove the need for a cycle. TypeError: undefined is not...
Read more >
React and Redux: Require cycle (how to get rid of it?) - Reddit
React throws me a warning like, come on man, don't do that. ... In Frontend JavaScript In The Real World (With React Code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found