electron-updater Version: 1.11.0I'm creating an Electron app using (:star2: the awesome :tada:) electron-builder.
My app is written in TypeScript, I think that is (ironically) causing the problem.
When I try to compile with tsc (./node_modules/.bin/tsc`) I get the error:
node_modules/electron-builder-http/out/electron-builder-http.d.ts(257,31): error TS2503: Cannot find namespace 'debug'.
When I open that file in the editor I see a:
protected readonly debug: debug.Debugger
with the debug.Debugger showing the error: Cannot find namespace 'debug'.
Looking at the official types for debug I see that there's a declaration compatible to the one in this repo under "typings". But it is not being used, and during compiling it seems like none of those two is used.
mkdir test-electron-builder
cd test-electron-builder
package.json with:{
"name": "test-electron-updater",
"version": "1.0.0",
"main": "out/index.js",
"license": "MIT",
"devDependencies": {
"@types/electron": "^1.4.34",
"electron": "^1.6.2",
"electron-builder": "^16.3.0",
"typescript": "^2.2.1"
},
"dependencies": {
"electron-updater": "^1.11.0"
},
"build": {
"appId": "com.example.test-electron-updater"
}
}
tsconfig.json with:{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true,
"outDir": "out"
},
"include": [
"src/**/*"
]
}
src/index.ts with:import * as electron from 'electron';
import { autoUpdater } from 'electron-updater';
yarn install
tsc:./node_modules/.bin/tsc
it throws:
node_modules/electron-builder-http/out/electron-builder-http.d.ts(257,31): error TS2503: Cannot find namespace 'debug'.
I can "fix" it locally by:
cd node_modules/electron-builder-http/
debug:yarn add @types/debug
electron-builder-http.d.ts, importing debug. Changing the section:declare module "electron-builder-http" {
/// <reference types="node" />
import { EventEmitter } from "events"
to
declare module "electron-builder-http" {
/// <reference types="node" />
import * as debug from 'debug';
import { EventEmitter } from "events"
@types interface. Changing the section: export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
protected readonly maxRedirects: number
protected readonly debug: debug.Debugger
export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
protected readonly maxRedirects: number
protected readonly debug: debug.IDebugger
I'm right now working on a PR but I'm not sure I'm approaching it as you (the maintainer) would want it.
I see that the problem is specific to the module electron-builder-http. I also see there are typings in the top level of the project.
And I see in the source that those types are included in the tsconfig.json with a:
...
"files": [
"../../typings/debug.d.ts"
]
...
but it seems like those types are not being exported to the final npm module, so I can't use them in a TypeScript based project.
My current approach is to add @types/debug as a dependency to electron-builder-http and change the interface to debug.IDebug.
Thanks for clear report.
Workaround — add
"skipLibCheck": true
to tsconfig.js as in the ts project https://github.com/develar/onshape-desktop-shell/blob/master/tsconfig.json
Thanks @develar !
That works. :tada:
I almost finished the change to make all the parts use the semi-official types from @types/debug.
Is that something that interests you?
If doing that interests you, I'm having a problem running the tests with yarn run test.
I just resetted the files to remove all my changes with git checkout -- . but even with the pure source files the same error occurs.
I would like to know if I'm any step or if it's a genuine bug / issue.
I made all the changes to use @types/debug in several places that the library is used, but I woudn't like to create a PR while the tests are not passing yet.
Official types/debug is bad and must be not used, because global var debug is exported.
About tests — please provide error details. Did you clone project using git lfs?
Oh! Sorry! I though I had copy-pasted the logs.
Here's the last part:
Building packages/electron-builder-util
Generating d.ts to /media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/out/electron-builder-util.d.ts
Building packages/electron-publish
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/bluebird-lst/index.d.ts (803, 3): Duplicate identifier 'default'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/fs-extra-p/index.d.ts (3, 12): Duplicate identifier 'WriteStream'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/fs-extra-p/index.d.ts (3, 25): Duplicate identifier 'createReadStream'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/fs-extra-p/index.d.ts (3, 43): Duplicate identifier 'createWriteStream'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/fs-extra-p/index.d.ts (3, 62): Duplicate identifier 'FSWatcher'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/fs-extra-p/index.d.ts (3, 73): Duplicate identifier 'Stats'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/node_modules/fs-extra-p/index.d.ts (5, 15): Duplicate identifier 'Filter'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/bluebird-lst/index.d.ts (803, 3): Duplicate identifier 'default'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/fs-extra-p/index.d.ts (3, 12): Duplicate identifier 'WriteStream'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/fs-extra-p/index.d.ts (3, 25): Duplicate identifier 'createReadStream'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/fs-extra-p/index.d.ts (3, 43): Duplicate identifier 'createWriteStream'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/fs-extra-p/index.d.ts (3, 62): Duplicate identifier 'FSWatcher'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/fs-extra-p/index.d.ts (3, 73): Duplicate identifier 'Stats'.
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/node_modules/fs-extra-p/index.d.ts (5, 15): Duplicate identifier 'Filter'.
error Command failed with exit code 255.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
OK, thanks for the clarification about the official @types/debug types. I'll just stick to your suggested workaround.
Then we can then close this now if that seems OK to you.
PR will be accepted. Later someone will fix official typIngs
Tests — do not install node modules for sub packages. Please remove all node_modules except root. Did you install it manually by mistake?
Yeah — we should use official types to avoid such issues for users.
I will hide debug member from http request lib, so, it will be not exposed.
Wow! You're fast @develar ! I was just going to "start to continue working on it" when I saw that you already did a lot about it.
Thanks for the great project and the commitment to it.
Nevertheless, I just installed the version you just released on that same demo project commented above, using yarn add [email protected] and the error is still present:
â–¶ ./node_modules/.bin/tsc
node_modules/electron-updater/node_modules/electron-builder-http/out/electron-builder-http.d.ts(257,31): error TS2503: Cannot find namespace 'debug'.
Do you want me to finish that PR I was trying and see if that would help (and if that would fit in the project)?
I started trying to finish the PR just to see where it could take me.
I installed and used git lfs.
I removed any node_modules inside the projects.
I added a dev dependency to the top package of @types/debug.
I refactored the debug imports to be like import * as _debug from "debug", etc.
But while running yarn run test I'm gettting an error.
I thought it could be that the debug types where trying to declare a global debug and not allowing to import it as import * as _debug from debug, so I "refactored" everything to use debug and export debugUtil instead, but I still got the same error:
Building test
yarn schema v0.22.0
$ typescript-json-schema packages/electron-builder/tsconfig.json Config --out packages/electron-builder/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks
Done in 3.82s.
Done in 25.69s.
yarn lint v0.22.0
$ node test/out/helpers/lint.js
/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/src/util.ts:13
export const debugUtil = debug("electron-builder")
^
TypeError: (0 , (_debug || _load_debug(...))) is not a function
at Object.<anonymous> (/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/packages/electron-builder-util/src/util.ts:13:26)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/media/user/DATA/temp-wd-code/wd-code/code2/electron-builder/test/src/helpers/lint.ts:7:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:393:7)
error Command failed with exit code 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I don't really understand what's happening (I actually don't understand how the full complex build works, without installing dependencies, etc).
Then I tried adding adding @types/debug as a dependency to the internal package, but I got the same error.
And then I tried to "install" the dependencies inside the internal package, but I got the same error as above in https://github.com/electron-userland/electron-builder/issues/1405#issuecomment-289146904
I'm kind of lost now.
I just wish it was possible to bundle the used types (your original type declarations) in a sub package in its "out" type declarations file, but it seems that's not possible...
Most helpful comment
Thanks for clear report.
Workaround — add
to tsconfig.js as in the ts project https://github.com/develar/onshape-desktop-shell/blob/master/tsconfig.json