Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write files #60

Closed
tezqa opened this issue Feb 9, 2018 · 8 comments
Closed

Write files #60

tezqa opened this issue Feb 9, 2018 · 8 comments

Comments

@tezqa
Copy link

tezqa commented Feb 9, 2018

Hi,

How to use the node fs module to write file when the game is running in Electron?

Thanks for your help!

@rroylance
Copy link
Owner

rroylance commented Feb 9, 2018

Hi @tezqa, I see no reason using fs as usual shouldn't work. w3schools has some good and easy to follow and try out examples.

@tezqa
Copy link
Author

tezqa commented Feb 9, 2018

Hi @rroylance

I had an error with webpack: Module not found: Error: Cannot resolve module 'fs'

But I solved by adding:

target: 'node',

But now I have a EACCESS error when trying to write my file.

@tezqa
Copy link
Author

tezqa commented Feb 9, 2018

Ok forget it, it was because of the path i chose. Thanks :)

@tezqa tezqa closed this as completed Feb 9, 2018
@tezqa
Copy link
Author

tezqa commented Feb 11, 2018

Hi @rroylance,

I'm trying to access to Electron from the app code in order to get specifics user paths.

import { app } from 'electron'
app.getPath('documents')

But I got undefined when I try to import Electron. Any idea?

@rroylance
Copy link
Owner

Hi @tezqa, you may need to require electron rather than importing it.

import app = require('electron'); // or something along these lines

@tezqa
Copy link
Author

tezqa commented Feb 11, 2018

I have tried to use require and import, but without success...

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again

It fails because of the node_modules/electron/index.js file:

var pathFile = path.join(__dirname, 'path.txt')

if (fs.existsSync(pathFile)) {
  module.exports = path.join(__dirname, fs.readFileSync(pathFile, 'utf-8'))
} else {
  throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
}

Indeed, __dirname is equal to / when the app is running.

I suppose there is something to configure in the webpack config.

@tezqa
Copy link
Author

tezqa commented Feb 11, 2018

Ok I ended up with the Nodejs os module to find the correct path. I don't use Electron.
But it's strange that nobody here needs to use Electron within the app.

@rroylance
Copy link
Owner

rroylance commented Feb 11, 2018

Hmm. Glad you got it working none the less. Unfortunately I don't even use the electron portion of this project at all so I'm pretty unfamiliar with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants