I'm trying to add the OneSignal SDK to my ReactNative project managed by Expo SDK, by following the guide here:
Expo One Signal
here is my plugin setup in App.js
export default function App() {
useEffect(() => {
///Other things
OneSignal.setAppId(Constants.manifest.extra.oneSignalAppId);
}, []);
unfortunately it doesn't work, first I was getting:
Invariant Violation: Native module cannot be null.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/#react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:204:6 in guardedLoadModule
at http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:263808:3 in global code
Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/#react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
Then, after opening an issue in GitHub the author suggested my to install:
yarn add react-native-onesignal
Here is the Issue on Github.Then I started getting:
iOS Bundling failed 3417ms
Unable to resolve module fs from /Users/giulioserra/Documents/App/CTS/node_modules/onesignal-expo-plugin/build/onesignal/withOneSignalIos.js: fs could not be found within the project or in these directories:
node_modules
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
29 | exports.xcodeProjectAddNse = exports.withOneSignalIos = void 0;
30 | const config_plugins_1 = require("#expo/config-plugins");
> 31 | const fs = __importStar(require("fs"));
I cleared the cache but nothing, It seems so strange since fs package should be included in every node release as far as I know, and suggestions?
Related
When I try to run the app, it crashes with the error below? I tried several methods for clearing the cashes, including uninstalling the resent package I installed on the app, but I couldn't figure out what was causing the error or how to fix it.
TypeError: undefined is not a function
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:95:4 in reportException
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:141:19 in handleException
at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
at node_modules\#react-native\polyfills\error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules\metro-runtime\src\polyfills\require.js:203:6 in guardedLoadModule
at http://192.168.2.5:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:247928:3 in global code
Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in error
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:95:4 in reportException
at node_modules\react-native\Libraries\Core\ExceptionsManager.js:141:19 in handleException
at node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in handleError
at node_modules\#react-native\polyfills\error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:370:8 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:113:4 in callFunctionReturnFlushedQueue
The following are the recently installed packages:
#react-native-community/datetimepicke
moment
the follwing is my env
Node: 16.15.0
Yarn: 1.22.15
expo: 45.0.0
react: "17.0.2"
react-native: "0.68.2"
So for some reason i'm having this bug when i try to run the app on the Expo Go app in my phone. Apparently is ok if i run on the web browser.
This is the error log
ReferenceError: Can't find variable: TextDecoder
Stack trace:
node_modules\expo\build\environment\react-native-logs.fx.js:27:4 in
error
node_modules\react-native\Libraries\Core\ExceptionsManager.js:95:4 in
reportException
node_modules\react-native\Libraries\Core\ExceptionsManager.js:141:19
in handleException
node_modules\react-native\Libraries\Core\setUpErrorHandling.js:24:6 in
handleError
node_modules#react-native\polyfills\error-guard.js:49:36 in
ErrorUtils.reportFatalError
node_modules\metro-runtime\src\polyfills\require.js:203:6 in
guardedLoadModule
http://192.168.0.29:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:190345:3
in global code ...
This happened to us too, on an app that had used to work in an older Expo version. The solution for us was to add this line to our .babelrc.js file:
"presets": [
["babel-preset-expo", {
lazyImports: true, // <<< The fix
]
]
Got over the problem by doing this;
npm install text-encoding
npm install big-integer
and pasting this code inside node_modules>react-native>Libraries>LogBox
const TextEncodingPolyfill = require('text-encoding');
const BigInt = require('big-integer')
Object.assign(global, {
TextEncoder: TextEncodingPolyfill.TextEncoder,
TextDecoder: TextEncodingPolyfill.TextDecoder,
BigInt: BigInt,
});
My React Native (0.66.3) app today pops up an error with a stable code which hasn't had any change for quite some time. It is on macOS Big Sur. Here is the error:
ERROR TypeError: undefined is not a function, js engine: hermes
Error: ENOENT: no such file or directory, open '/Users/macair/Documents/code/js/xyz_app5/http:/localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.xyz-app5'
at Object.openSync (fs.js:498:3)
at Object.readFileSync (fs.js:394:35)
at getCodeFrame (/Users/macair/Documents/code/js/xyz_app5/node_modules/metro/src/Server.js:919:18)
at Server._symbolicate (/Users/macair/Documents/code/js/xyz_app5/node_modules/metro/src/Server.js:992:22)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Server._processRequest (/Users/macair/Documents/code/js/xyz_app5/node_modules/metro/src/Server.js:403:7) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/Users/macair/Documents/code/js/xyz_app5/http:/localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.xyz-app5'
}
Here is the error displayed on IOS simulator:
The error seems related to metro in React Native.
Reinstall node_modules
rm -rf node_modules
Clean your cache
yarn cache clean (or npm cache clean βforce)
After creating a new eslint-plugin for a custom rule, vue-cli-service build fails (eslint works as expected, when triggered by ./node_modules/.bin/eslint --ext .js,.vue,.json ./ --max-warnings=0).
GitHub repository reproducing issue
Starting in an environment with a working vue-cli-service build, following the simplified instructions at https://blog.webiny.com/create-custom-eslint-rules-in-2-minutes-e3d41cb6a9a0, also reproduces the issue. Running vue-cli-service build after every step, it starts failing after step 4: yarn add --dev file:./eslint, and the build still fails after all the steps are completed.
Error message:
ERROR Failed to compile with 32 errors
Module build failed (from ./node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js):
TypeError: eslint.CLIEngine is not a constructor
at Object.module.exports (MYPATH/node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js:223:27)
***repeats 31 more times***
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
vue-cli-service build stills fails after running yarn install, which says it is already up to date.
Most results for this specific TypeError: eslint.CLIEngine is not a constructor error claim the user should upgrade their JetBrains IDE. However, I am running vue-cli-service build on the command line and not using JetBrains.
The code referred to by the error message is (with preceding context):
MYPATH/node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js
...
var config = assign(
// loader defaults
{
cacheIdentifier: JSON.stringify({
"eslint-loader": pkg.version,
eslint: eslintVersion || "unknown version"
}),
eslintPath: "eslint"
},
userOptions
);
if (typeof config.formatter === "string") {
try {
config.formatter = require(config.formatter);
if (
config.formatter &&
typeof config.formatter !== "function" &&
typeof config.formatter.default === "function"
) {
config.formatter = config.formatter.default;
}
} catch (_) {
// ignored
}
}
var cacheDirectory = config.cache;
var cacheIdentifier = config.cacheIdentifier;
delete config.cacheIdentifier;
// Create the engine only once per config
var configHash = objectHash(config);
if (!engines[configHash]) {
var eslint = require(config.eslintPath);
engines[configHash] = new eslint.CLIEngine(config); //Error happens here
}
...
Edit: I upgraded #vue/cli-plugin-eslint from version 3.11.0 to 4.1.2 by editing yarn's package.json, at the suggestion of #DelenaMalan below. The build still fails with error:
ERROR Failed to compile with 1 errors 7:51:01 PM
Module build failed (from ./node_modules/#vue/cli-service/node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
at PoolWorker.fromErrorObj (MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:262:12)
at MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:204:29
at mapSeries (MYPATH/node_modules/neo-async/async.js:3625:14)
at PoolWorker.onWorkerMessage (MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:170:35)
at readBuffer (MYPATH/node_modules/#vue/cli-service/node_modules/thread-loader/dist/WorkerPool.js:152:14)
at Object.module.exports (MYPATH/node_modules/#vue/cli-plugin-eslint/node_modules/eslint-loader/index.js:223:27)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR Build failed with errors.
error Command failed with exit code 1.
Edit 2:
I deleted and reinstalled the node modules on the repro linked here, as recommended by #CGundlach, but I still have the eslint.CLIEngine is not a constructor error
Annas-MacBook-Pro:eslint-test-project anna$ rm -rf node_modules/
Annas-MacBook-Pro:eslint-test-project anna$ yarn install
yarn install v1.21.1
[1/4] π Resolving packages...
[2/4] π Fetching packages...
[3/4] π Linking dependencies...
warning "#vue/eslint-config-airbnb > eslint-import-resolver-webpack#0.11.1" has unmet peer dependency "webpack#>=1.11.0".
[4/4] π¨ Building fresh packages...
β¨ Done in 14.14s.
Annas-MacBook-Pro:eslint-test-project anna$ yarn build
yarn run v1.21.1
$ vue-cli-service build
β Building for production...
ERROR Failed to compile with 1 errors 12:28:32 PM
Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
at PoolWorker.fromErrorObj (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:262:12)
at /Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:204:29
at mapSeries (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/neo-async/async.js:3625:14)
at PoolWorker.onWorkerMessage (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:170:35)
at readBuffer (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/thread-loader/dist/WorkerPool.js:152:14)
at Object.module.exports (/Users/anna/projects/yarn-vue-eslint/eslint-test-project/node_modules/eslint-loader/index.js:223:27)
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR Build failed with errors.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Make sure all warnings are resolved when you run either npm ci, npm i or yarn install. For me the following warnings were showed after doing a fresh install:
$ vue-cli-service build
β § Building for production...
ERROR Failed to compile with 1 error 20:47:55
Syntax Error: Thread Loader (Worker 0)
eslint.CLIEngine is not a constructor
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
When I did a fresh install and resolved the peer dependency issue by decreasing my eslint version everything works as expected.
So try to downgrade your eslint dependency to the correct version. For me I had to downgrade to eslint < 7.0.0.
npm i -D eslint#6.8.0
# or yarn
yarn add -D eslint#6.8.0
I'm trying to run a react native app in expo, and after creating a blank app with expo init, when I cd into my project and do expo start, I get the following error:
events.js:282
throw er; // Unhandled 'error' event
^
Error: unable to resolve root /Users/myusername/Documents/native-app-name: failed to opendir(/Users/myusername/Documents/native-app-name): Operation not permitted
at BunserBuf.<anonymous> (/Users/myusername/Documents/native-app-name/node_modules/fb-watchman/index.js:95:23)
at BunserBuf.emit (events.js:305:20)
at BunserBuf.process (/Users/myusername/Documents/native-app-name/node_modules/bser/index.js:292:10)
at /Users/myusername/Documents/native-app-name/node_modules/bser/index.js:247:12
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Emitted 'error' event on WatchmanWatcher instance at:
at Client.<anonymous> (/Users/myusername/Documents/native-app-name/node_modules/jest-haste-map/build/lib/WatchmanWatcher.js:130:10)
at Client.emit (events.js:305:20)
at BunserBuf.<anonymous> (/Users/myusername/Documents/native-app-name/node_modules/fb-watchman/index.js:107:12)
at BunserBuf.emit (events.js:305:20)
at /Users/myusername/Documents/native-app-name/node_modules/bser/index.js:249:12
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
watchmanResponse: {
version: '4.7.0',
error: 'unable to resolve root /Users/myusername/Documents/native-app-name: failed to opendir(/Users/myusername/Documents/native-app-name): Operation not permitted'
}
}
Why might this be?
Try to move your project folder to a different place on your local. I just tried and worked for me.