long.js
long.js copied to clipboard
"./package.json" is not defined by "exports" warning in React Native
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"
Similar problem happening here.
The long.js functionalities doesn't seems to be affected, but this warning can be quite annoying.
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);
}
});
}