Skip to content

(reading files issue) ENOENT: no such file or dicrectory - fs:js.640 #6911

Closed

Description

@chito256
  • Electron version: 1.3.3
  • Operating system: Ubuntu Linux 16.04 LTS

Hi, I am trying to read a json file using NodeJS's fs module. The path is correct, but when the app runs, it could not find the file.

Here is the block of code in a file called index.js:

// index.js
const fs = window.require('fs');
const path = window.require('path');

// get configuration file
const data = fs.readFileSync(path.join(__dirname, 'config.json'), 'utf8');
const config = JSON.parse(data);

Here is my app's structure:
screenshot from 2016-08-20 19-58-49

The BrowserWindow then responded with this:
screenshot from 2016-08-20 20-00-59

fs:js.640 then pointed to this:
screenshot from 2016-08-20 20-03-09

I know this sounds like a problem with NodeJS, but I got the same code working outside of the app.
I hope this can be fixed, thanks in advance! :)

Activity

  1. vsemozhetbyt commented on Aug 20, 2016

    @vsemozhetbyt
    Contributor

    @shuliandre Do you use the same version of Node in Electron and in outside testing? There was some big fs fix in the last Node. BTW, is your app in somehow virtual drive? This also can cause problems for Node older than 6.4.0

  2. enlight commented on Aug 20, 2016

    @enlight
    Contributor

    I'm guessing __dirname is an empty string because you're using Webpack or something like it.

    FYI, GitHub issues are for bug reports and feature requests, for everything else see the community.

  3. chito256 commented on Aug 20, 2016

    @chito256
    Author

    @vsemozhetbyt Hi, the current version of NodeJS on my machine is 6.4.0. I'm not sure how I can check its version in Electron though, can you suggest a way for me to do it? Thanks 😄
    @enlight Yes I am using Webpack, but even if I only specify the path as path.join('config.json', 'utf8');, it still wouldn't work. And yes I knew about the Electron community, Slack is my prefered choice but I haven't used it much, I will try to use the community more often 😄 Thanks for your reply 😄

  4. chito256 commented on Aug 20, 2016

    @chito256
    Author

    @vsemozhetbyt Oh I checked the Node version in Electron and it's currently 6.3.0, is there a way for me to upgrade to the latest version?

  5. vsemozhetbyt commented on Aug 20, 2016

    @vsemozhetbyt
    Contributor

    @shuliandre I am afraid not untill the Electron upgrade it. But we are not sure this is the issue yet. So is your app in the virtual drive?

  6. chito256 commented on Aug 20, 2016

    @chito256
    Author

    @vsemozhetbyt No I am not using a virtual drive, I only use webpack-dev-server and start the server and the app separately (through 2 Terminal).

  7. MarshallOfSound commented on Aug 20, 2016

    @MarshallOfSound
    Member

    @shuliandre The issue is probably due to how webpack inlines __dirname

    However as @enlight said

    FYI, GitHub issues are for bug reports and feature requests, for everything else see the community.

    If you need help check out the discussion forums or Slack please 👍

  8. chito256 commented on Aug 20, 2016

    @chito256
    Author

    @MarshallOfSound Okay, thanks for your support! 👍

  9. MarshallOfSound commented on Aug 20, 2016

    @MarshallOfSound
    Member

    @shuliandre FYI

    webpack/webpack#1599

  10. chito256 commented on Aug 20, 2016

    @chito256
    Author

    @MarshallOfSound Oh so that was the issue, this is the first time I encounter it 😄 Thanks Samuel! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions