Compile with nexe the main process electron js? - javascript

Is it possible to compile the main process of electron main.js with some tool? I am using nexe to compile the main process main.js but it doesn't work.Is there a way to do that?
I am using https://github.com/electron/electron-quick-start
Then I use nexe main.js to generate a compilation.
Then I modify package.json by changing the value of main.js to main.exe.
Finally npm start and I get an error message:
MZ´┐¢
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at loadApplicationPackage (C:\Users\Onimac\AppData\Roaming\npm\node_modules\electron\dist\resources\default_app.asar\main.js:109:16)
at Object.<anonymous> (C:\Users\Onimac\AppData\Roaming\npm\node_modules\electron\dist\resources\default_app.asar\main.js:155:9)
at Module._compile (internal/modules/cjs/loader.js:967:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
Minified main.js code:
const {app, BrowserWindow} = require('electron');
function createWindow () {
const mainWindow = new BrowserWindow({
width: 800,
height: 600
})
mainWindow.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
})

Related

Why nodejs didnt require p-queue?

I want to use p-queue npm nodejs. But it get me error. Help me why it was and how to fix it? Here my code:
const shell = require("shelljs");
const async = require("async");
const fs = require("fs");
const path = require("path");
const { default: PQueue } = require("p-queue");
const queue = new PQueue({ concurrency: 1 });
And this error:
internal/modules/cjs/loader.js:1080
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module:
C:\Users\Feruz\Desktop\codeMaster\judge\node_modules\p-queue\dist\index.js
require() of ES modules is not supported. require() of
C:\Users\Feruz\Desktop\codeMaster\judge\node_modules\p-queue\dist\index.js
from C:\Users\Feruz\Desktop\codeMaster\judge\judge.js is an ES module
file as it is a .js file whose nearest parent package.json contains
"type": "module" which defines all .js files in that package scope as
ES modules. Instead rename index.js to end in .cjs, change the
requiring code to use import(), or remove "type": "module" from
C:\Users\Feruz\Desktop\codeMaster\judge\node_modules\p-queue\package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\Feruz\Desktop\codeMaster\judge\judge.js:5:29)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) { code: 'ERR_REQUIRE_ESM' } [nodemon] app crashed - waiting for file
changes before starting...

NODE [ERR_MODULE_NOT_FOUND]: Cannot find module './config/app'

FIXED, the names of the folders in my pc changed when uploaded to github
So, my app looks something like this
├── config
| ├── app.js
|
└── index.js
app.js
Here i have all my env variables, so I have a central point from which to extract them
require('dotenv').config()
module.exports = {
appPort: process.env.PORT,
appUrl: process.env.APP_URL,
appKey: process.env.APP_KEY,
frontendUrl: process.env.FRONTEND_URL
}
index.js
central file of the server
const express = require('express')
const cors = require('cors')
const app = express()
const { appPort, frontendUrl } = require('./config/app')
app.listen(appPort , () => {
console.log(`Server listening on port ${appPort}`);
})
The problem here is that when i deploy it and starts the server, it throws me error
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './config/app'
Require stack:
- /app/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/app/index.js:8:34)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/app/index.js' ]
}
and i really don't know why, because it works perfectly fine in my pc
the code for the whole project is actually much bigger, but only this files are the ones throwing me errors
Hope someone can help see what is happening that throws that error

Gulp SyntaxError: Invalid or unexpected token

I just made an script to compile our scss when we save the file with gulp but I execute "gulp sass" I receive the next error:
gulp.task('sass', function () => {
^
SyntaxError: Invalid or unexpected token
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at requireOrImport (C:\Users\smartinc\AppData\Roaming\npm\node_modules\gulp-cli\lib\shared\require-or-import.js:19:11)
at execute (C:\Users\smartinc\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:37:3)
at Liftoff.handleArguments (C:\Users\smartinc\AppData\Roaming\npm\node_modules\gulp-cli\index.js:211:24)
This is the code:
const gulp = require('gulp');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
// Creates the task that will compile our scss
gulp.task('sass', () => {
// TODO: Must be a way to call a variable with scss route
return gulp.src('./cartridges/peru/cartridge/client/default/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./cartridges/peru/cartridge/static/default/css'));
});
The thing is that it works just fine in my computer but it doesnt work in my partner's computer.
I have no clue of what could be happening.
Any help?

Error Deploying VueJs App (Laravel) - ReferenceError: window is not defined

I have this problem at the time of deploying Vue with Laravel.
I have node js 12 and laravel 6 installed, everything is correct but when I start the application I get that error:
/var/www/vhosts/domain.com/cl.domain.com/resources/js/app.js:3
global.window = window;´
ReferenceError: window is not defined
at Object.<anonymous> (/var/www/vhosts/domain.com/cl.domain.com/resources/js/app.js:3:17)
at Module._compile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:681:19)
at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at require (internal/modules/cjs/helpers.js:16:16)
at loadApplication (/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/usr/share/passenger/helper-scripts/node-loader.js:214:2)
My code:
require('./bootstrap');
window.Vue = require('vue');
require('vue-flash-message');
require('vue-flash-message/dist/vue-flash-message.min.css');
Vue.use(VueFlashMessage);

Node and Require import error in Mocha?

I have a working Node application and I'm trying to add Mocha tests, but getting some odd import errors.
This is my file structure:
package.json
index.js
src/
chart.js
highcharts-options.js
test/
test_chart.js
This is what my chart.js file looks like:
var chartOptions = require('./highcharts-options');
var analyseChart = {
doSomething: function() { ... }
};
module.exports = analyseChart;
And this is what highcharts-options.js looks like:
var HighCharts = require('highcharts-browserify');
Highcharts.theme = { ... };
Currently I import everything from /src into a single index.js file, then bundle it with browserify, which works just fine, no errors in the application.
Now I want to start writing Mocha tests for the functions in /src.
This is my first stub in test_chart.js:
var chart = require('../src/chart');
chart.doSomething();
But when I run mocha, I get the following error:
Users/.../js/src/highcharts-options.js:11
Highcharts.theme = {
^
ReferenceError: Highcharts is not defined
at Object.<anonymous> (/Users/.../js/src/highcharts-options.js:11:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/.../js/src/chart.js:7:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/.../js/test/test_chart.js:1:75)
How can I fix this import error for Mocha?
var HighCharts = require('highcharts-browserify');
Highcharts.theme = { ... };
You have a spelling error.
High[cC]harts
How did you not notice this yourself even when you were told exactly what was wrong?
Some errors are so common that we ultimately stop trusting them, and start looking for other faults in our code without even investigating it.
This is especially true for the "someVar is undefined" error in javascript.
Takeaway:
Sometimes you just got to trust your error messages.

Categories