I was looking for a way to add Vue Devtools to the electron app I was working on. I tried a couple of methods that seemed to be outdated and finally succeded using this package:
electron-devtools-installer which I installed as a DEV dependency.
with this code:
import { app } from 'electron'
import installExtension from 'electron-devtools-installer';
const VUEJS3_DEVTOOLS = 'nhdogjmejiglipccpnnnanhbledajbpd';
...
app.whenReady().then(() => {
installExtension(VUEJS3_DEVTOOLS)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
});
but since this was a DEV dependency, the app fails to load due to the missing package in production.
I was wondering if there is a way to dynamicly load the package/extension only if not in production.
It took me many attempts to figure this out since this isn't directly documented anywhere and I lack the experience of loading ES6 modules to think of trying module.default.default.
This is the code that ended up working without issues in both development and production cases:
app.whenReady().then(() => {
if (process.env.DEBUGGING) // replace with whatever you use to check for dev env
import('electron-devtools-installer')
.then(mymodule => {
const installExtension = mymodule.default.default; // Default export
installExtension(mymodule.default.VUEJS_DEVTOOLS) // replace param with the ext ID of your choice
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
}).catch((err) => console.log('An error occurred: ', err));
}).catch((err) => console.log('An error occurred: ', err));
There might be a more elegant way to do this but this is all I needed. I am open to hear improvements on this.
Note: replace mymodule.default.VUEJS_DEVTOOLS with any other valid Chrome extension ID. The package has some popular ones built-in: Electron DevTools Installer - GitHub
Related
I am running into an issue where I am running multiple tests using supertest and jest. When there is only one test running then it works just fine but the second one throws the following error:
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
I tested this with two very simple tests:
describe("Default API", () => {
describe("Default:", () => {
it("should create a user in the DB", (done) => {
request(app).get("/").expect(200, done);
});
it("should create a user in the DB", (done) => {
request(app).get("/").expect(200, done);
});
});
});
They are the same but the second one throws the error. If I run only the first one there is no issue. This must be a setup issue Does anyone have advice. In my index.ts where I have the main express code I export app as follows:
export default app;
This is at the bottom of the index.ts file.
I had the simular problem and toggle down the issue, in my case I want to use mysql2 to access mariadb. That Module try to autodetect the charset and do to try to lacy loading that encoding.
But I have not found a solution for that for now.
I am currently working on reading a local file in react-native and am running into the following error,
TypeError:null is not an object(evaluating 'RNFSManager.RNFSFileTypeRegular')
The code I am using is taken straight off of the documentation for react-native-fs , using the basic example, from the examples section:
// require the module
var RNFS = require('react-native-fs');
// get a list of files and directories in the main bundle
RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)
.then((result) => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
if (statResult[0].isFile()) {
// if we have a file, read it
return RNFS.readFile(statResult[1], 'utf8');
}
return 'no file';
})
.then((contents) => {
// log the file contents
console.log(contents);
})
.catch((err) => {
console.log(err.message, err.code);
});
If it helps I am using vs when writing this on a Windows 10 computer.
I have tried resetting my cache, reinstalling react-native-fs, and linking react-native-fs, none have solved the problem all resulting in the same error.
I would greatly appreciate any help. Thank you.
In case of iOS message is 'Native module cannot be null', In Android message is 'null is not an object evaluating RNFSManager etc'
Solution for iOS is run pod install in iOS Directory, then react-native run-ios to re-run the app.
Solution for android is react-native link react-native-fs then react-native run-android to re-run the app.
I have recently upgraded my react-native project to 0.60. After upgrading, a native module I have been working with has stopped working on iOS, with the error TypeError: Cannot read property 'show' of undefined.
I have been modifying this native module but the only code I had modified after upgrading to RN 0.60 was Android code. My modified module code is at https://github.com/BradyShober/react-native-braintree-dropin-ui
The file that is calling the module is
import BraintreeDropIn from 'react-native-braintree-dropin-ui';
const showBraintreeUI = async (token, amount) => {
BraintreeDropIn.show({
clientToken: token,
countryCode: 'US',
currencyCode: 'USD',
orderTotal: amount,
googlePay: true,
googleMerchantId: 'merchantID',
applePay: true,
merchantName: "Name",
merchantIdentifier: "ID",
vaultManager: true
})
.then(async (result) => {
console.log(result)
}
catch(error){
console.log(error);
}
})
.catch((error) => {
if (error.code === 'USER_CANCELLATION') {
console.log("User cancelled payment");
}
else {
console.log(error);
}
});
}
export { getBraintreeToken, showBraintreeUI };
The expected result is the opening of the Braintree Drop In UI which works on Android but on iOS is throwing an error TypeError: Cannot read property 'show' of undefined.
I believe this to be an issue with autolinking, I have been able to get it to work if I right click Libraries in Xcode, then Add files and select the module's .xcodeproject and then add the library in Link Binaries with Libraries. I haven't been able to easily find what I would have to change in the module to not have to do those steps as a workaround.
I was able to get it working thanks to some help I got on the Reactiflux discord server. The issue was due to an issue in the module's Podspec that was causing none of the module's source files to be detected. The s.source_files was set to s.source_files = "RNBraintreeDropIn/**/*.{h,m}" instead of s.source_files = "*.{h,m}"
I'm building a React Native application using create-react-native-app. The app connects to Priority via the API without error, however when I need to use the Web-SDK to get the options for a choose field it is throwing an error:
SDK Error: ReferenceError: Buffer is not defined
at btoa (C:\...\node_modules\btoa\index.js:8)
at b64encode (C:\...\node_modules\priority-web-sdk\index.js:2744)
at $FormQuery (C:\...\node_modules\priority-web-sdk\index.js:3898)
at $GetRows (C:\...\node_modules\priority-web-sdk\index.js:3957)
at Form_1.GetRows (C:\...\node_modules\priority-web-sdk\index.js:4673)
at C:\...\node_modules\priority-web-sdk\index.js:6234
at tryCallTwo (C:\...\node_modules\promise\setimmediate\core.js:45)
at doResolve (C:\...\node_modules\promise\setimmediate\core.js:200)
at new Promise (C:\...\node_modules\promise\setimmediate\core.js:66)
at Object.gform.getRows (C:\...\node_modules\priority-web-sdk\index.js:6233)
**Actual files paths edited for brevity/privacy.
My code that calls getRows()
return login(configuration)
.then(() => formStart('PORDERS', null, null, configuration.company, 1))
.then(form => myForm = form)
.then(() => myForm.setSearchFilter(filter))
.then(() => myForm.getRows(1))
.then(r => rows = r)
.then(() => myForm.setActiveRow(1))
.then(a => row = a)
.then(() => myForm.choose('STATDES',rows.PORDERS[row.rowindex].STATDES))
.then((response) => {return response.ChooseLine})
.catch(err => console.log('SDK Error: ', err));
This issue popped up recently. It was working fine before. I thought maybe I had upgraded a package incorrectly, so I reverted to a previous version of the yarn.lock file and rebuilt the node_modules folder, but with no success.
I feel like this is more of a yarn/npm package or Priority issue than React-native, but I'm at a loss. Any suggestions on what else I could do?
Update:
The more I work on this and the more I try different things, it feels to me more and more like an issue of my test setup having different native functions than my live set up. Any suggestions on how to check/solve that?
This is fixed in version 1.9.3 of priority-web-sdk.
In addition, here is a link to Priority Master app's repository that is built with react-native: https://github.com/PrioritySoftware/priority-master-react.
N.B. First time posting, so please don't hesitate to correct formatting errors, question form, etc.
I'm relatively new to react-native and but trying to build an app that makes changes to a google sheet using their API. I found a package to handle the OAuth authentication (repo-linked-here) but it seems to be throwing the following error:
TypeError: undefined is not an object (evaluating 'Module[fn]')
Here is most of my index.android.js:
...
import OAuthManager from 'react-native-oauth';
const manager = new OAuthManager('App');
export default class App extends Component {
constructor(props){
super(props);
this.state = {
isSignedIn: false
};
}
componentDidMount(){
manager.configure({
google: {
callback_url: 'http://localhost/google',
client_id: '*************',
client_secret: '************'
}
})
.then(resp => console.warn(resp))
.catch(err => console.warn(err));
}
...
React-native-oauth seems to indicate that if I use 'http://localhost/google' for the callback and add a few lines to the build.gradle file, then the callbacks/linking should work fine.
Any and all advice would be appreciated!
I think your are not calling authorize from manager. Also you can't add then & catch to configure:
componentDidMount(){
manager.configure({
google: {
callback_url: 'http://localhost/google',
client_id: '*************',
client_secret: '************'
}
});
manager.authorize('google', {scopes: 'profile email'})
.then(resp => console.warn(resp))
.catch(err => console.warn(err));
}
Maybe someone else had this problem .
I also had this error message and spend a lot of time to find any solution , and none of founded answers resolved my issue .
The problem was neither configure or authorise .
When you run (cd ios && pod install) and try to link it's asking you to overwrite pods file . Say YES .
I found it by running app from xcode , then get error message like :
framework not found DCTAuth
Then googling and found that it is related with pods file .
Hope this will help someone .