windows - Vite-electron configuration for own js logic code - Stack Overflow
I am new to electron-vite with react. My project has a http node server process. All related files are place in server named folder. The vite folder structure is main, renderer and preload. I have placed server folder in src, that means it is main, renderer, preload and server folder. server.js is there in server folder. Below is the line of code which fails
serverProcess = fork(path.join(__dirname, '../sync/server.js'), {
env: { PORT: 9090 }
})
it fails with, Cannot find module 'D:\codebase\syncer\out\server\server.js
package.json has "main": "./out/main/index.js",
It tries to find the server code in out folder. I don't know what to mention (configuration) to use all folder and files in server folder. The platform is windows 11. please help me.
I am new to electron-vite with react. My project has a http node server process. All related files are place in server named folder. The vite folder structure is main, renderer and preload. I have placed server folder in src, that means it is main, renderer, preload and server folder. server.js is there in server folder. Below is the line of code which fails
serverProcess = fork(path.join(__dirname, '../sync/server.js'), {
env: { PORT: 9090 }
})
it fails with, Cannot find module 'D:\codebase\syncer\out\server\server.js
package.json has "main": "./out/main/index.js",
It tries to find the server code in out folder. I don't know what to mention (configuration) to use all folder and files in server folder. The platform is windows 11. please help me.
1 Answer
Reset to default 0One approach is copying the server folder into the final build using extraResources
in the electron-builder config:
"build": {
"extraResources": [
{ "from": "server", "to": "server" }
]
}
The script can then be referenced by checking if it’s development or production:
const isDev = process.env.NODE_ENV === 'development';
const serverPath = isDev
? path.join(__dirname, '../server/server.js')
: path.join(process.resourcesPath, 'server', 'server.js');
const serverProcess = fork(serverPath, { env: { PORT: 9090 } });
That way, server.js
is included in the build, preventing the “Cannot find module” error.
- 下个月Win7正式“退休”,数据显示国内近60%电脑用户仍在使用
- 与微信支付宝较量有难度 解析Apple Pay入华细节
- 消息称PC供应商面临来自Windows 8的挑战
- Why does this typecheck in Lean? - Stack Overflow
- electron - Windows task scheduler triggers the task but it is not invoking the app which I want to open on system login - Stack
- frontend - Rescript and Fetch with Post Request - Stack Overflow
- IMDB pagination-container for a series in python - Stack Overflow
- typescript - Declare object and internally refer to other values - Stack Overflow
- c++ - inlining failed in call to ‘always_inline’ ‘vld1q_u16’ - cross compiling Node.js for armv6 - Stack Overflow
- python - Tkinter: custom frame widget overrides columnconfigure - Stack Overflow
- combinatorics - MiniZinc - Optimizing Script for Scheduling Problem - Stack Overflow
- matlab - How do I update pixelClassificationLayer() to a custom loss function? - Stack Overflow
- c# - Make custom file property columns show by default in Windows File Explorer - Stack Overflow
- Optional parentheses for C variadic macro (i.e. both function-like and object-like) - Stack Overflow
- Angular lib with route - Stack Overflow
- javascript - Turning a horizontal scroll image gallery for desktop (using vertical scroll gesture) into a vertical scroll galler
- javascript - <function name> error: FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been