Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron and Webpack ENOENT: no such file or directory, open '/path.txt'

I am a beginner trying to use Electron (formerly Atom) and Reactjs bundled with Webpack. Everything was working fine until I tried to use Electron's remote module to access the mainWindow in my React components.

Trying to import this module, I get the infamous error: Uncaught Error: ENOENT: no such file or directory, open '/path.txt'

I've tried reinstalling electron and I've checked node_modules/electron, and found that path.txt is there.

Here is my webpack.config.js:

var webpack = require('webpack');

module.exports = {
    context: __dirname,
    entry: {
        app: ['webpack/hot/dev-server', './src/App.jsx'],
    },
    target: 'node',
    output: {
        path: './public/built',
        filename: 'bundle.js',
        publicPath: 'http://localhost:8080/built/'
    },
    devServer: {
        contentBase: './public',
        publicPath: 'http://localhost:8080/built/'
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                include: /src/,
                query: {
                    presets: ['es2015', 'react']
                }
            },
            {
                test: /\.(png|jpg)$/,
                loader: 'file-loader?name=[path][name].[hash].[ext]'
            },
            {
                test: /\.css$/,
                loader: 'style-loader!css-loader'
            }
        ]
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
}

And here is my package.json:

{
  "name": "app",
  "version": "0.1.0",
  "main": "main.js",
  "description": "description",
  "license": "UNLICENSED",
  "repository": {
    "type": "git",
    "url": "https://github.com"
  },
  "scripts": {
    "start": "./node_modules/.bin/electron .",
    "watch": "./node_modules/.bin/webpack-dev-server"
  },
  "dependencies": {
    "electron": "^1.3.5",
    "radium": "^0.17.1",
    "react": "^15.0.1",
    "react-dom": "^15.0.1"
  },
  "devDependencies": {
    "babel": "^6.5.2",
    "babel-core": "^6.7.7",
    "babel-loader": "^6.2.4",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "css-loader": "^0.24.0",
    "file-loader": "^0.9.0",
    "style-loader": "^0.13.1",
    "webpack": "^1.13.0",
    "webpack-dev-server": "^1.14.1"
  }
}

I suspect that it may have something to do with the start script in package.json as the path.txt is not in the same directory as node_modules/.bin/electron. However, I haven't figured out how to solve this.

like image 748
knguyen2525 Avatar asked Sep 09 '16 21:09

knguyen2525


1 Answers

in case it's not to late, you simply need to replace your "node" target with "electron-renderer" in your webpack.config.js

like image 122
brunorzn Avatar answered Sep 26 '22 07:09

brunorzn