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

TypeError: Cannot read property 'style' of undefined #262

Open
davidbiller opened this issue Dec 10, 2020 · 1 comment
Open

TypeError: Cannot read property 'style' of undefined #262

davidbiller opened this issue Dec 10, 2020 · 1 comment

Comments

@davidbiller
Copy link

davidbiller commented Dec 10, 2020

React Native WEB:

Module.../../../react-native-circular-progress/src/CircularProgress.js
node_modules/react-native-circular-progress/src/CircularProgress.js:130

@RonAmihai
Copy link

This issue appears with many RN libraries which are still using ViewPropTypes (like react-native-router-flux for example).

Those libraries should remove ViewPropTypes usage (it's deprecated by RN anyway) or simply do runtime availability check:
(ViewPropTypes ? ViewPropTypes.style : PropTypes.object)

However, as temporary fix, the above can be done in a post-install script (this can be simplified even more, this code is just for demonstration):

 /* eslint-disable @typescript-eslint/no-var-requires */
const projectRootPath = require("app-root-path");
const path = require("path");
const fixFiles = require("replace-in-file");

const nodeModulesPath = path.join(projectRootPath.toString(), "node_modules");

const fixViewPropTypesStyleOptions = {
    from: /ViewPropTypes.style/g,
    to: "(ViewPropTypes ? ViewPropTypes.style : PropTypes.object)",
};

const fixReactNativeRouterFluxViewPropTypesStyleOptions = {
    files: path.join(nodeModulesPath, "react-native-router-flux/**/*"),
    ...fixViewPropTypesStyleOptions,
};

const fixReactNativeCircularProgressPropTypesStyleOptions = {
    files: path.join(nodeModulesPath, "react-native-circular-progress/**/*"),
    ...fixViewPropTypesStyleOptions,
};

async function fixReactNativeRouterFlux() {
    try {
        await fixFiles.replaceInFile(fixReactNativeRouterFluxViewPropTypesStyleOptions);
        console.log("Fixed react-native-router-flux successfully");
    } catch (error) {
        console.error("Failed to fix react-native-router-flux with the following error:", error);
    }
}

async function fixReactNativeCircularProgress() {
    try {
        await fixFiles.replaceInFile(fixReactNativeCircularProgressPropTypesStyleOptions);
        console.log("Fixed react-native-circular-progress successfully");
    } catch (error) {
        console.error("Failed to fix react-native-circular-progress with the following error:", error);
    }
}

(async function postInstall() {
    await fixReactNativeRouterFlux();
    await fixReactNativeCircularProgress();
})();

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

2 participants