I am building a simple electron app using react, i needed to use the os.homedir method to get the home directory of the user.
Here is my react component,
import React, { Component } from 'react'
import Os from 'os'
export default class Item extends Component {
constructor( props ) {
super( props )
}
render () {
return (
<div className='item-component'>
{ Os.homedir() }
</div>
)
}
}
But seems that electron is not utilizing the os module of node js. Thus an
Uncaught TypeError: _os2.default.homedir is not a function
error occures.
Instead of importing the os
module i also used the require
method with no luck.
let Os = require( 'os' )
How to use node modules in electron and react setup?
You can clone it to test ....
I know this is like 4 months late... but if it helps now try using let Os = window.require( 'os' )
.
In my app that i'm developing using react and electron if i did not say window.require
I would get the same error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With