electron-updater: Can not find module 'debug' - node.js

I am developing Desktop App(windows/mac) using Electronjs. I was trying to implement auto-update feature using electron-updater since I am using electron-builder for the building.
I am able to generate .exe file for my app but when trying to install, it's throwing an error: "Can not find module 'debug'". Please find attached screenshot.
Without electron-updater implementation, my app is running fine. When I am importing autoUpdator in my index.js, started getting that error. I am using autoUpdator as below:
const {autoUpdater} = require("electron-updater");
autoUpdater.on('update-downloaded', (ev, info) => {
setTimeout(function() {
autoUpdater.quitAndInstall();
}, 5000)
})
app.on('ready', ()=> {
autoUpdater.checkForUpdates();
});
Please find the libraries description below:
"electron-updater": "^4.0.6"
"electron": "^3.0.6"
"electron-builder": "^20.38.4"
I followed below links:
Electron builder Auto Update
electron builder using local server
I am new to the Electron js actively looking for your support.
As asked please find my build configuration below:
"build": {
"appId": "com.****.*****",
"productName": "********",
"directories": {
"output": "build"
},
"publish": [
{
"provider": "generic",
"url": "http://127.0.0.1:4080/"
}
],
"nsis": {
"oneClick": false,
"perMachine": true,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": true,
"createDesktopShortcut": true
},
"win": {
"target": "nsis"
},
"files": [
"!**/.vscode",
"!**/build",
"!**/config",
"!**/assets/data",
"!**/src"
],
"extraResources": [
{
"from": "src/assets/data",
"to": "dist/assets/data",
"filter": "database*"
}
]
},

The line "!**/src" in your exclude list is the culprit.
Many node modules will have "src" folders which have to be packaged/bundled along with your application source code.
If you observe "debug" module folder under "node_modules" it has a "src" folder which has been excluded by above rule.
Suggestion: If you have your apps source folder as "src", rename it to something else like "source" (which is in your control), but ensure you don't exclude "src" folders of node_modules (renaming these is not in your control as it could break the module's integrity and they get overwritten on fresh npm install also)

Related

Webpack bundling but not resolving typescript from node_modules package

Question guys, I've tried about every different way I can think of to solve this.
We have two folders in a makeshift mono-repo (no yarn workspace). One called Mgt-Shared one called Server. We reference shared from Servers package.json with "mgt-shared": "file:../mgt-shared", and I run a simple npm install to get our shared into Servers node_modules.
Both projects are mixed typescript and javascript.
When I run webpack to attempt to bundle server, it works fine, the Typescript files from shared show up in the bundle list but when I run the node dist/app.bundle.js - it can't resolve some of the modules (specifically all the typescript ones).
When I run webpack --json I find this (which seems like it's resolving properly):
{
"id": "mgt-shared/discounts/discount_reasons",
"identifier": "external \"mgt-shared/discounts/discount_reasons\"",
"name": "external \"mgt-shared/discounts/discount_reasons\"",
"index": 23,
"index2": 15,
"size": 42,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [
"main"
],
...
"failed": false,
"errors": 0,
"warnings": 0,
"assets": [],
"reasons": [
{
"moduleId": "./src/discounts/discount.ts",
"moduleIdentifier": "/home/mygastank/WebstormProjects/mygastank/server/node_modules/babel-loader/lib/index.js!/home/mygastank/WebstormProjects/mygastank/server/src/discounts/discount.ts",
"module": "./src/discounts/discount.ts",
"moduleName": "./src/discounts/discount.ts",
"type": "cjs require",
"userRequest": "mgt-shared/discounts/discount_reasons",
"loc": "20:24-72"
},
{...
],
"providedExports": null,
"optimizationBailout": [],
"depth": 6
},
My webpack config is this:
const nodeExternals = require('webpack-node-externals')
module.exports = {
mode: 'development',
target: 'node',
// This forces resolution of native node modules
externals: [nodeExternals({ modulesFromFile: true })],
entry: './src/index',
output: {
filename: 'app.bundle.js'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)?$/,
loader: 'babel-loader',
include: [/node_modules\/mgt-shared/],
exclude: [/node_modules/],
options: {
presets: [
[
'env',
{
'targets': {
'node': 'current'
}
}
],
['#babel/preset-typescript',
{ 'allExtensions': true, 'isTSX': true }]
]
}
}]
}
}
I found that there was a way to whitelist other directories.
I needed to add the whitelist key to the options for nodeExternals like so:
externals: [nodeExternals({
whitelist: [/mgt-shared/],
modulesFromFile: true
})],
Everything else was able to stay the same.

cmd eslint can not find ts error which found by IDE

I want to use eslint in cmd to check ts file, but it can not get error info which I got in IDE.
I have set #typescript-eslint/parser in eslintrc.js. And eslint which running in cmd gave me some ts error when I did some wrong. But some wrong else did not be found.
I have a ts file with code:
interface Item {
name: string;
age: number;
}
const config: Array<Item> = [{
name: 'foo',
}]
so, I got some error in IDE:
Property 'age' is missing in type '{ name: string; age: number }' but required in type 'Item'.ts(2741)
That right. I need this error info.
But when I run eslint in cmd
eslint fileName.ts or eslint --ext .ts fileName.ts
cmd eslint return nothing or some other warning/error in this file.
eslintrc here
module.exports = {
"extends": ["xxx"],
"globals": {
"__SERVER_ENV__": true,
},
"rules": {
"react/jsx-filename-extension": 0,
"no-console": ["warn", { allow: ["error", "warn"] }],
"#typescript-eslint/no-unused-vars": ["error", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": true
}],
},
"settings": {
"react": {
"createClass": "createReactClass", // Regex for Component Factory to use,
// default to "createReactClass"
"pragma": "React", // Pragma to use, default to "React"
"version": "detect", // React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
},
"import/parsers": {
"#typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
// use <root>/tsconfig.json
"typescript": {
// always try to resolve types under `<roo/>#types` directory even it doesn't contain any source code, like`#types/unist`
"alwaysTryTypes": true,
"directory": "./",
},
},
},
"parser": "#typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
},
},
"plugins": ["#typescript-eslint", "import"],
};
and tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"noImplicitAny": true,
"module": "commonjs",
"lib": ["es6","dom","es2017"],
"target": "es5",
"jsx": "react",
"types":["react"],
"outDir": "/output",
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
},
"allowSyntheticDefaultImports": true,
"sourceMap": true
},
"awesomeTypescriptLoaderOptions": {
"useWebpackText": true,
"useTranspileModule": true,
"doTypeCheck": true,
"forkChecker": true
},
"include": [
".d.ts",
"./src/**/*"
]
}
I hope to get whole error info by cmd. what should I do?
It appears that eslint by design will not perform your Typescript type checking. I am just running my build command locally using tsc to be notified of this "property missing in type" error message, and fixing when the build fails.
It's very inconvenient because I only get alerted to one error per build attempt. If anyone has a better solution I'd appreciate any help.

Using environment variables in nx based nodejs app

I've setup a project with several nodejs and angular apps inside a nrwl/nx workspace.
I'm trying to work with the environment files
inside the nodejs apps.
I've setup the import like this:
import {environment} from './environments/environment';
Then I ran ng serve my-node-app and it shows the environment for non production.
Now I tried to do ng serve my-node-app --prod to see how the app works with a production setup - but I get the error:
Configuration 'production' could not be found in project my-node-app.
Here's the project's angular.json config:
"ui-server": {
"root": "apps/ui/server",
"sourceRoot": "apps/ui/server/src",
"projectType": "application",
"prefix": "ui-server",
"schematics": {},
"architect": {
"build": {
"builder": "#nrwl/builders:node-build",
"options": {
"outputPath": "dist/apps/ui/server",
"main": "apps/ui/server/src/main.ts",
"tsConfig": "apps/ui/server/tsconfig.app.json",
"assets": ["apps/ui/server/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"fileReplacements": [
{
"replace": "apps/ui/server/src/environments/environment.ts",
"with": "apps/ui/server/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "#nrwl/builders:node-execute",
"options": {
"buildTarget": "ui-server:build"
}
},
"lint": {
"builder": "#angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/ui/server/tsconfig.app.json",
"apps/ui/server/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**"]
}
},
"test": {
"builder": "#nrwl/builders:jest",
"options": {
"jestConfig": "apps/ui/server/jest.config.js",
"tsConfig": "apps/ui/server/tsconfig.spec.json"
}
}
}
}
Am I missing something?
I've found this post when I was looking how to fetch the environmental variables defined in .env file.
process.env.ENVIRONMENTAL_VARIABLES in frontend part can be accessed when rendering on the server (e.g. Angular Universal), having .env in the root of Nrwl monorepo and webpack properties, such as:
const dotenv = require('dotenv-webpack');
module.exports = {
plugins: [
new dotenv(),
],
};
Don't forget to change your angular.json:
...
"architect": {
"build": {
"builder": "#angular-builders/custom-webpack:browser",
"options": {
"customWebpackConfig": {
"path": "./webpack.browser.config.js",
"replaceDuplicatePlugins": true
},
...
I've named the custom webpack as webpack.browser.config.js.
Now, let say you have a server/..., which you're using for some backend stuff, then you won't have them accessible there. You need to install dotenv package and in the server/main.ts, let say that's your server's root, require this package, that way:
require('dotenv').config();
Note: until Angular 8 we were able to set up also webpack-server related logic, in a file such as webpack.server.config.js. Therefore, it was doable to apply basically same code related to dotenv, which was in webpack.browser.config.js. However, it doesn't work anymore. Angular CLI Builders are being used to build & server SSR apps instead.
Deploying to Firebase/using Cloud Functions for Firebase (and possibly other Serverless/FaaS)?
Then in your functions folder you need to paste the .env file as well. I assume here that from functions you're deploying.
For debugging I'd advise:
console.log(require('dotenv').config({ debug: true }));
Might save you a lot of time.

auto-update files are deleted after auto-update

Hello everyone I build the installer with nsis ia32 arch, I use sqlite3 and everything works fine until the update is downloaded since it replaces all the files in the installation folder.
Then my database file is deleted, how can I prevent my database file from being deleted with the new versions?
Here I initialize my connection
export default class Connection {
private connection;
public initConnection(isTest) {
this.connection = new (sqlite3.verbose()).Database('filename.db');
}
.
.
.
}
Here my build config
"build": {
"win": {
"target": [{
"target": "nsis",
"arch": ["ia32"]
}],
"icon": "src/assets/images/icons/icon256.ico",
"publisherName": "spaces"
},
"publish": {
"provider": "spaces",
"name": "<space-name>",
"region": "nyc3"
}
}
electron-builder v19.33.0
electron-updater v2.10.1
thanks o/

JSPM System.import 404s

I am trying to learn JSPM as it seems like it is the future for installing client-side JavaScript. I am NOT attempting to use ES6 or TypeScript but am actually using CoffeeScript which I compile into 'standard' JavaScript for the browser. I am running node.js in express with my public files contained in ./public and accessible from the path /.
Having installed jspm my package.json configuration is:
"jspm": {
"directories": {
"baseURL": "public",
"packages": "public/lib"
}
}
It is configured like so:
System.config({
baseUrl: '/',
defaultJSExtensions: true,
transpiler: false,
paths: {}
});
With this setup I run: jspm install lodash which installs the package in public/lib/npm/lodash#4.5.1. In my application JavaScript I would expect to be able to run:
System.import('lodash');
and would expect that to return a Promise. However, I get a 404 on /lodash.js. So, in an effort to fix this I decided to use the explicit path to lodash: lib/npm/lodash#4.5.1/lodash. That seems to resolve the lodash 404 but then I get a 404 for /buffer.js and /process.js which I assume are dependencies of lodash.
Surely there has to be a better way than this? What am I missing here?! Part of the difficulty I am having is that most of the examples seem to use ES6 import directives which are irrelevant to me.
It seems that you are missing some paths on your systemjs config:
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: false,
paths: {
"github:*": "lib/github/*",
"npm:*": "lib/npm/*"
},
map: {
"lodash": "npm:lodash#4.6.1",
...
"npm:lodash#4.6.1": {
"buffer": "github:jspm/nodelibs-buffer#0.1.0",
"process": "github:jspm/nodelibs-process#0.1.2"
},
...
}
});
Also, you should have the lodash dependency declared on your package.json:
{
"jspm": {
"directories": {
"baseURL": "public",
"packages": "public/lib"
},
"dependencies": {
"lodash": "npm:lodash#^4.6.1"
}
}
}

Resources