Error: Unable to resolve module crypto from /node_modules/azure-iot-common/dist/authorization.js: crypto could not be found within the project or in these directories:
node_modules
../node_modules
5 | Object.defineProperty(exports, "__esModule", { value: true });
6 | exports.hmacHash = exports.stringToSign = exports.encodeUriComponentStrict = exports.anHourFromNow = void 0;
Installed packages
"azure-iot-provisioning-device": "^1.9.1", "azure-iot-provisioning-device-mqtt": "^1.8.1", "azure-iot-security-symmetric-key": "^1.8.2",
Error: Unable to resolve module crypto from /node_modules/azure-iot-common/dist/authorization.js: crypto could not be found within the project or in these directories: node_modules ../node_modules 5 | Object.defineProperty(exports, "__esModule", { value: true }); 6 | exports.hmacHash = exports.stringToSign = exports.encodeUriComponentStrict = exports.anHourFromNow = void 0;
Using in react native bare project.
shims.js
import 'react-native-url-polyfill/auto'; import 'react-native-get-random-values'; import 'text-encoding-polyfill'; const getRandomValues = global.crypto.getRandomValues; import * as crypto from 'isomorphic-webcrypto'; global.crypto = crypto; global.crypto.getRandomValues = getRandomValues;