Set a custom entry file for Metro dev server in React Native build - react-native

I'm writing some scripts that do custom React Native builds for unit testing and such, specifying a custom entry file for the react-native-xcode.sh script using the ENTRY_FILE env variable. This is super useful and great. I'm able to do release builds no problem, and they work just fine, so basically I can build a RN app from any entry file at will. However, when I try a Debug variant build, metro doesn't seem to know about my special custom entry file, and gives me this error:
None of these files exist:
* index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
* index/index(.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)
at ModuleResolver.resolveDependency (/Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:165:15)
at ResolutionRequest.resolveDependency (/Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
at DependencyGraph.resolveDependency (/Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/node-haste/DependencyGraph.js:285:16)
at /Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/lib/transformHelpers.js:267:42
at Server.<anonymous> (/Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/Server.js:841:41)
at Generator.next (<anonymous>)
at asyncGeneratorStep (/Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/Server.js:99:24)
at _next (/Users/justin/dev/enmesh/testutilsnative/node_modules/metro/src/Server.js:119:9)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
IN RESOLVER
Error: Unable to resolve module `./index` from ``:
Does anyone know how I can get the Debug build of the app to interface properly with the Metro development server, so I can debug my app builds better? Any guidance here would be greatly appreciated!
Metro is just getting launched automatically by the xcodebuild process, which I'm calling like this:
const args = {
simulator: device,
configuration: variant,
scheme,
projectPath: xcodeProjectPath,
device: undefined,
uuid: undefined,
packager: true,
verbose: true,
port: 8081,
terminal: undefined,
};
const xcodebuildSpawnOptionsArgs: any = {
...args,
cwd: folder,
env: {
PLATFORM: 'ios',
ENTRY_FILE: builtEntryFilePath,
},
};
const buildProcess = spawn(
'xcodebuild',
xcodebuildArgs,
getProcessOptions(xcodebuildSpawnOptionsArgs),
);

Related

WebdriverIo is not able to initialize wdio-rerun-service : Getting below error

[0-13] 2022-05-25T04:33:05.332Z DEBUG #wdio/utils:initialiseServices: initialise service "selenium-standalone" as NPM package
[0-13] 2022-05-25T04:33:05.350Z DEBUG #wdio/utils:initialiseServices: initialise service "RerunService" as NPM package
[0-13] 2022-05-25T04:33:05.351Z ERROR #wdio/utils:initialiseServices: Error: Couldn't find plugin "RerunService" service, neither as wdio scoped package "#wdio/rerunservice-service" nor as community package "wdio-rerunservice-service". Please make sure you have it installed!
at Object.initialisePlugin [as default] (/Users//dotor/dot-or-automation/node_modules/#wdio/runner/node_modules/#wdio/utils/build/initialisePlugin.js:26:11)
at initialiseServices (/Users/****/dotor/dot-or-automation/node_modules/#wdio/runner/node_modules/#wdio/utils/build/initialiseServices.js:24:51)
at Object.initialiseWorkerService (/Users//dotor/dot-or-automation/node_modules/#wdio/runner/node_modules/#wdio/utils/build/initialiseServices.js:67:26)
at Runner.run (/Users/*******/dotor/dot-or-automation/node_modules/#wdio/runner/build/index.js:43:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
[0-13] Capabilities: {"maxInstances":2,"browserName":"chrome","acceptInsecureCerts":true,"goog:chromeOptions":{}}
[0-13] 2022-05-25T04:33:05.437Z DEBUG #wdio/sync: Finished to run "beforeSession" hook in 0ms
2022-05-25T04:33:05.800Z DEBUG #wdio/local-runner: Runner 0-13 finished with exit code 0
2022-05-25T04:33:05.800Z INFO #wdio/cli: [0-13] SKIPPED in chrome - /automation/features/ui/Others/setting-wheel.feature
2022-05-25T04:33:05.800Z INFO #wdio/cli:launcher: Run onWorkerEnd hook
Not sure if you already found your answer for this but if you haven't. The webdriverio doc explains it well.
// wdio.conf.js
const RerunService = require('wdio-rerun-service');
export.config = {
// ...
services: [RerunService, {
// ...
}]
};
This service is slightly configured differently compared to the other ones.
Note that we are importing the service and using it in the config object. Other services are usually called directly after installation, and the name of the service is usually a string example:
export.config = {
// ...
services: ["selenium-standalone", {
// ...
}]
};

metro error 'crypto', package itself specifies a `main` module field that could not be resolved, react-native and open api

running react native with ios simulator.
the backend uses open api, and has a folder in FrontEnd, to enforce schemas. I'm calling a class from this openapi auto generated file Frontend/sdk/api.ts.
in my frontend/service/doSomething.ts,
import { DefaultApi } from '../sdk/api // in frontend, autogenerated by open API
function func1 () {
const api = new DefaultApi() // calls crypto somehow
}
on build, i get this error
BUNDLE ./index.js
error: Error: While trying to resolve module `crypto` from file
`/app/node_modules/request/lib/helpers.js`, the package
`/app/node_modules/crypto/package.json` was successfully found.
However, this package itself specifies a `main` module field that
could not be resolved (`/app/node_modules/crypto/index.js`. Indeed,
none of these files exist:
* /app/node_modules/crypto/index.js(.native|.ios.jsx|.native.jsx|.jsx|.ios.js|.native.js|.js|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.json|.native.json|.json)
* /app/node_modules/crypto/index.js/index(.native|.ios.jsx|.native.jsx|.jsx|.ios.js|.native.js|.js|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.json|.native.json|.json)
at DependencyGraph.resolveDependency (/app/node_modules/metro/src/node-haste/DependencyGraph.js:311:17)
at Object.resolve (/app/node_modules/metro/src/lib/transformHelpers.js:129:24)
at resolve (/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:396:33)
at /app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:412:26
at Array.reduce (<anonymous>)
at resolveDependencies (/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:411:33)
at processModule (/app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:140:31)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async addDependency (/node_modules/metro/src/DeltaBundler/traverseDependencies.js:230:18)
at async Promise.all (index 2)
Failed: I've tried following However, this package itself specifies a `main` module field that could not be resolved adding to metro.config.js
resolver: {
sourceExts: ['jsx', 'js', 'ts', 'tsx'], //add here
}
but it FAILS with same error.
the request package and crypto has been deprecated.

How to configure with create-react-native-app metro bundler

I'm new to react-native, this community is awesome.
but i'm having an issue with configuring https://github.com/terrylinla/react-native-sketch-canvas with npx create-react-native-app .
all I've done so far is edit the metro.config.js
const extraNodeModules = {
'#terrylinla/react-native-sketch-canvas': './node_modules/#terrylinla\react-native-sketch-canvas/'
}
const resolverMainFields = ['browser','main'];
module.exports = {
resolver: {
extraNodeModules,
resolverMainFields
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
then cmd react-native run-android it bundles correctly but it never loads onto the emulator:
this is what it says in shell:
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
(node:8712) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
Jetifier found 987 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
Configure project :terrylinla_react-native-sketch-canvas
WARNING: Configuration 'provided' is obsolete and has been replaced with 'compileOnly'.
It will be removed soon. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Task :app:stripDebugDebugSymbols UP-TO-DATE
Compatible side by side NDK version was not found.
<============-> 99% EXECUTING [10m 30s]
IDLE
IDLE
:app:installDebug
IDLE
So I just got metro to bundle my js files correctly. I discovered it was something to do with the react-native android gradle it's very confusing. But I just restarted my computer and ran the same commands. That fixed it.
these stackoverflow answers worked before for me to get my build working:
Stuck on info starting JS server
React-native run-android stuck at 99% appDebug
I hope this helps to anyone using create-react-native-app & metro-bundler

ReferenceError: ReadableStream is not defined while running jest tests

My web app reads local files using a custom ReadableStream (in-order that I won't need to have a max file size that the platform supports) and it works great, both for correctly formatted files and error files. My app is built using React-Redux-Saga.
I'm now attempting to add limited e2e tests to my code to test the state management. I'm testing that when sending redux actions the state updates correctly. I'm testing the saga's using the package redux-saga-tester.
While running the jest client tests that read local files using the ReadableStream I built, I got an error ReferenceError: ReadableStream is not defined. What I understood is that the jsdom environment that jest uses is missing the ReadableStream implementation. I than added the web-streams-polyfill package to polyfill the ReadableStream class.
Now the validate file test is passing as in the browser:
test('Select and validate log file', async () => {
const testFile = testFileBuilder.valid();
storeTester.dispatch(fileSelected(testFile));
await storeTester.waitFor(FILE_VALIDATED);
const state = storeTester.getState().file;
expect(state.fileValidated).toBeTruthy();
});
My problem is that when I run a second validation test with an invalid file the test passes but prints an error to the console.
The test:
test('Select an invalid file - JSON error', async () => {
const testFile = testFileBuilder.errorJSON();
storeTester.dispatch(fileSelected(testFile));
await storeTester.waitFor(FILE_ERROR);
const state = storeTester.getState().file;
expect(state.fileValidated).toBeFalsy();
expect(state.fileError).toBeTruthy();
});
The error that is printed after the test completes successfully:
e.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (/home/noams/dev/web/visual-log-viewer/client/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19)
at Request.client.on.err (/home/noams/dev/web/visual-log-viewer/client/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:676:20)
at Request.emit (events.js:194:15)
at Request.onRequestError (/home/noams/dev/web/visual-log-viewer/client/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:189:13)
at Socket.socketErrorListener (_http_client.js:392:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19) undefined
Any subsequent file validation tests fail.
I'd appreciate any advice of how to tackle this issue.

WebStorm: Karma server not starting, TypeError: undefined is not a function on server.start();

I have the latest version of WebStorm (10.0.4). Today I wanted to include karma in my project so I installed Python and ran:
npm install -g karma
npm install karma
npm install karma-jasmine
npm install karma-chrome-launcher
npm install karma-phantomjs-launcher
I tried it with two different config files, one for my project and one superbasic config, but both throw the same error. Here is the basic config:
// Karma configuration
// Generated on Fri Jul 17 2015 14:05:46 GMT+0200 (Mitteleuropäische Sommerzeit)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'test/**/*Spec.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}
I then created a new "Karma" Run configuration, but when I click run, it says:
"C:\Program Files\nodejs\node.exe" "C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\plugins\js-karma\js_reporter\karma-intellij\lib\intellijServer.js" --karmaPackageDir=C:\workspace\full_ui\node_modules\karma --configFile=C:\workspace\full_ui\tests\karma.conf_messages.js --browsers=Chrome
C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\plugins\js-karma\js_reporter\karma-intellij\lib\intellijServer.js:10
server.start(cliOptions);
^
TypeError: undefined is not a function
at Object.<anonymous> (C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\plugins\js-karma\js_reporter\karma-intellij\lib\intellijServer.js:10:8)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Process finished with exit code 1
I really don't know what could cause this problem. Did I miss anything to install? I have never used karma before, so I might have some basic error somewhere, but I can't figure out what.
I think this may be caused by a recent update to the karma lib 9 days ago
https://github.com/karma-runner/karma/commits/master/lib/server.js
It could be the intellijServer.js is now out of date and needs to be altered. I've got it working by updating the intellijServer.js (until intellij fix it) with:
var cli = require('./intellijCli.js')
, Server = cli.requireKarmaModule('lib/server.js')
, cliOptions = { configFile: require.resolve('./intellij.conf.js') };
var browsers = cli.getBrowsers();
if (browsers != null) {
cliOptions.browsers = browsers;
}
var server=new Server(cliOptions);
server.start();
// Prevent karma server from being an orphan process.
// For example, if WebStorm is killed using SIGKILL, karma server will still be alive.
// When WebStorm is terminated, karma server's standard input is closed automatically.
process.stdin.resume();
process.stdin.on('close', function () {
// terminating orphan process
process.exit(123);
});
Once I got the server bit working i got another issue with No provider for “framework:jasmine”! (However this appears to be a separate unrelated issue affecting me, because I didn't fully setup karma).
This was resolved with:
npm install karma-jasmine --save-dev
npm install karma-chrome-launcher --save-dev
followed by
npm install