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

"./package.json" is not defined by "exports" warning in React Native #126

Open
leonardogbxv opened this issue Aug 24, 2023 · 2 comments
Open

Comments

@leonardogbxv
Copy link

Description

A warning alert from long.js package is being outputed on command line when running "react-native run-android" on React Native.

Output

This is the command line output.

warn Package long has been ignored because it contains invalid configuration. Reason: Package subpath "./package.json" is not defined by "exports" in /../.../node_modules/long/package.json

Additional information

"long": "5.2.3"
"react-native": "0.64.4"
"react": "16.13.1"
"node": "16.17.0"
@leonardogbxv
Copy link
Author

Similar problem happening here.

The long.js functionalities doesn't seems to be affected, but this warning can be quite annoying.

@leonardogbxv
Copy link
Author

leonardogbxv commented Aug 24, 2023

A workaround for now. You can run it on the "postinstall" of your package.json project.

function fixLongExportWarning() {
  const packagePath = 'node_modules/long/package.json';

  fs.readFile(packagePath, 'utf8', (readError, data) => {
    if (readError) {
      return console.error("['fixLongExportWarning' Read Error]", readError);
    }

    try {
      const packageData = JSON.parse(data);

      // add new field
      packageData.exports['./package.json'] = './package.json';

      // replace current package.json
      fs.writeFile(packagePath, JSON.stringify(packageData, null, 2), 'utf8', (writeError) => {
        if (writeError) {
          console.error("['fixLongExportWarning' Write Error]", writeError);
        }
      });
    } catch (error) {
      console.error("['fixLongExportWarning' Error]", error);
    }
  });
}

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

1 participant