I'm currently working on a project using Electron, Typescript, and webpack. I am planning to integrate react.js into the project.
However, when I ran "npx webpack" in the terminal, I encountered an error message.
The error stated that the "electron-is-dev" module could not be found, even though I had already installed it.
ERROR in ./src/main/window.ts
Module not found: Error: Can't resolve 'electron-is-dev' in 'project-path/src/main'
@ ./src/main/window.ts 2:0-36 12:35-40
@ ./src/main/app.ts
I have been unable to find a solution to this issue.
window.ts
import { app, BrowserWindow } from 'electron';
import isDev from 'electron-is-dev';
(...)
webpack.config.js
const path = require('path');
module.exports = [
{
target: 'electron-main',
entry: path.join(__dirname, 'src/main/app.ts'),
mode: 'development',
module: {
rules: [
{
test: /\.ts$/,
include: path.join(__dirname, 'src/main'),
use: 'ts-loader',
exclude: [
/node_modules/,
path.join(__dirname, 'src/renderer')
]
}
]
},
output: {
path: path.join(__dirname, 'build'),
filename: 'electron.js'
},
resolve: {
extensions: ['.tsx', '.ts', 'js']
},
node: {
__dirname: false
}
}
];
package.json:
{
"name": "electron-react-typescript",
"version": "0.0.1",
"description": "",
"main": "build/electron.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/electron-devtools-installer": "^2.2.0",
"@types/react": "^16.9.19",
"@types/react-dom": "^16.9.5",
"@typescript-eslint/eslint-plugin": "2.x",
"@typescript-eslint/parser": "2.x",
"babel-eslint": "10.x",
(...)
},
"dependencies": {
"electron-devtools-installer": "^2.2.4",
"electron-is-dev": "^1.1.0",
"react": "^16.12.0",
"react-dom": "^16.12.0"
}
}
Additionally, I am utilizing eslint and prettier in my development workflow.