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

I'm a newbie trying to use Electron (formerly Atom) and Reactjs bundled with Webpack. Everything worked fine until I tried to use the Electron electronic module to access mainWindow in my React components.

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

I tried reinstalling the electron, and I checked the 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 .json package:

{
  "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 this may have something to do with the start of the script in package.json, as the path.txt file is not in the same directory as node_modules /. bin / electronic. However, I did not understand how to solve this.

+4
2

, "node" "-" webpack.config.js

+6

,

cd node_modules/electron && node install.js

path.txt

Mac ,

dist/Electron.app/Contents/MacOS/Electron
0

Source: https://habr.com/ru/post/1654179/


All Articles