electron: os.homedir is not a function when using Babel

Hi, I’m creating electron application using React and Babel. My problem only occurs in files being transpiled with Babel. When I call:

const os = require('os');
// import os from 'os'; - same result
os.homedir();

it throws TypeError: os.homedir is not a function. The os property is not undefined it just lacks the homedir() function:

os

And as I said outside of the files transpiled with Babel, everything works properly. Do you know why is that?

Electron version: 1.4.11 Operating system: macOS Sierra v. 10.12.1

UPDATE: I’ve also noticed that same problem occurs with the fs package. But when I require it, then it’s just an empty object.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 15 (6 by maintainers)

Most upvoted comments

This boilerplate is using Webpack which IMHO is messy. Moreover this boilerplate is too complicated and I like simple solutions. I know that I don’t need Browserify or Webpack when working with Electron but I need them for JSX transpilation.

I think it’s very common that developers are using React with Electron and it would be a good idea to at least include some example in docs to make it more friendly for newcomers.

GitHub issues are for feature requests and bug reports, questions about using Electron should be directed to the community or to the Slack Channel.

@jagi You don’t need browserify or webpack for Electron (or anything like that) as you have a full commonjs environment.

I.e. You can just use require and it will work

If you want some pointers on React with Electron there is a boilerplate here that I hear good things about 👍

https://github.com/chentsulin/electron-react-boilerplate