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.
in case it's not to late, you simply need to replace your "node" target with "electron-renderer" in your webpack.config.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With