Skip to content

Commit dbdcb35

Browse files
committed
fix windows path resolution
1 parent 62a3456 commit dbdcb35

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

main.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,82 @@ const { app, BrowserWindow } = require('electron');
44
const path = require('path');
55
const fs = require('fs');
66

7-
// Get the correct path for the .next directory
87
const nextDir = path.join(process.resourcesPath, '.next');
98

10-
// Check if production build exists
119
const buildIdPath = path.join(nextDir, 'BUILD_ID');
1210
if (!fs.existsSync(buildIdPath)) {
1311
console.error('ERROR: No Next.js production build found.');
1412
console.error('Expected build at:', nextDir);
1513
process.exit(1);
1614
}
1715

18-
// For AppImage, we need to ensure Node.js can find all dependencies
19-
// Add the resources path to NODE_PATH
20-
process.env.NODE_PATH = `${process.resourcesPath}/app/node_modules:${process.resourcesPath}/.next/static/chunks`;
16+
if (process.platform === 'win32') {
17+
const nodeModulesPath = path.join(process.resourcesPath, 'app', 'node_modules');
18+
const nextStaticPath = path.join(nextDir, 'static', 'chunks');
19+
20+
process.env.NODE_PATH = [
21+
nodeModulesPath,
22+
nextStaticPath,
23+
process.env.NODE_PATH || ''
24+
].join(path.delimiter);
25+
26+
require('module').Module._nodeModulePaths(nodeModulesPath);
27+
require('module').Module._nodeModulePaths(nextStaticPath);
28+
} else {
29+
process.env.NODE_PATH = `${process.resourcesPath}/app/node_modules:${process.resourcesPath}/.next/static/chunks`;
30+
}
31+
2132
require('module').Module._initPaths();
2233

34+
if (process.platform === 'win32') {
35+
const requiredNextFiles = [
36+
path.join(process.resourcesPath, 'app', 'node_modules', 'next', 'dist', 'compiled', 'next-server', 'app-page.runtime.prod.js'),
37+
path.join(process.resourcesPath, 'app', 'node_modules', 'react', 'jsx-runtime.js')
38+
];
39+
40+
for (const file of requiredNextFiles) {
41+
if (!fs.existsSync(file)) {
42+
console.warn('Missing file (may be packed in asar):', file);
43+
44+
const alternativePaths = [
45+
path.join(process.resourcesPath, 'app.asar.unpacked', 'node_modules', 'next', 'dist', 'compiled', 'next-server', 'app-page.runtime.prod.js'),
46+
path.join(__dirname, 'node_modules', 'next', 'dist', 'compiled', 'next-server', 'app-page.runtime.prod.js'),
47+
];
48+
49+
for (const altPath of alternativePaths) {
50+
if (fs.existsSync(altPath)) {
51+
console.log('Found alternative at:', altPath);
52+
break;
53+
}
54+
}
55+
}
56+
}
57+
}
58+
2359
const nextApp = next({
2460
dev: false,
2561
dir: process.resourcesPath,
2662
conf: {
2763
distDir: '.next',
28-
// Disable features that require write access
2964
generateBuildId: () => 'static-build',
30-
// Disable webpack watching
3165
webpack: (config) => {
3266
config.watch = false;
67+
if (process.platform === 'win32') {
68+
config.resolve = config.resolve || {};
69+
config.resolve.fallback = config.resolve.fallback || {};
70+
config.resolve.fallback.path = require.resolve('path-browserify');
71+
}
3372
return config;
3473
},
3574
experimental: {
36-
// Increase timeout for static generation
37-
staticPageGenerationTimeout: 1000
75+
staticPageGenerationTimeout: 1000,
76+
esmExternals: false
3877
}
3978
}
4079
});
4180

4281
const handle = nextApp.getRequestHandler();
4382

44-
// Ensure single instance
4583
if (!app.requestSingleInstanceLock()) {
4684
app.quit();
4785
}
@@ -57,14 +95,14 @@ function createWindow() {
5795
contextIsolation: true,
5896
nodeIntegration: false,
5997
enableRemoteModule: false,
98+
webSecurity: true,
99+
allowRunningInsecureContent: false
60100
},
61-
// Disable font warnings
62101
show: false
63102
});
64103

65104
mainWindow.setMenuBarVisibility(false);
66105

67-
// Wait for window to be ready before showing to avoid font warnings
68106
mainWindow.once('ready-to-show', () => {
69107
mainWindow.show();
70108
});
@@ -76,7 +114,6 @@ function createWindow() {
76114
});
77115
}
78116

79-
// Initialize Next.js and create server
80117
nextApp.prepare().then(() => {
81118
server = createServer((req, res) => {
82119
return handle(req, res);
@@ -90,6 +127,8 @@ nextApp.prepare().then(() => {
90127

91128
console.log('> Production server ready on http://localhost:3000');
92129
console.log('> Serving from:', nextDir);
130+
console.log('> Platform:', process.platform);
131+
console.log('> NODE_PATH:', process.env.NODE_PATH);
93132
app.whenReady().then(createWindow);
94133
});
95134
}).catch(err => {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "print_mate",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --turbopack",
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
1010
"electron": "electron main.js",
11-
"package:linux": "next build && electron-builder --linux",
12-
"package:win": "next build && electron-builder --windows",
11+
"package:linux": "next build && electron-builder --dir --linux",
12+
"package:win": "next build && electron-builder --dir --windows",
1313
"package": "next build && electron-builder --dir -wl"
1414
},
1515
"dependencies": {

0 commit comments

Comments
 (0)