electron-updater throws "Cannot find namespace 'debug'" on TypeScript compile
See original GitHub issue- Version: 16.3.0
electron-updater
Version: 1.11.0
- Target: Linux / Windows (the error is thrown by TypeScript, before any compilation can happen)
Description
I’m creating an Electron app using (🌟 the awesome 🎉) 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.
Minimal steps to reproduce
- Create a directory for the test and enter it, in my case:
mkdir test-electron-builder
cd test-electron-builder
- Put a file
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"
}
}
- Put a file
tsconfig.json
with:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true,
"outDir": "out"
},
"include": [
"src/**/*"
]
}
- Create a file in
src/index.ts
with:
import * as electron from 'electron';
import { autoUpdater } from 'electron-updater';
- Install the dependencies:
yarn install
- Compile with
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'.
Workaround fix
I can “fix” it locally by:
- Entering the module directory:
cd node_modules/electron-builder-http/
- Installing the typings for
debug
:
yarn add @types/debug
- Modifying the file
electron-builder-http.d.ts
, importingdebug
. 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"
- And changing the type of the debug property below to use the
@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
Solution …?
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
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
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
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 globaldebug
and not allowing to import it asimport * as _debug from debug
, so I “refactored” everything to usedebug
and exportdebugUtil
instead, but I still got the same error: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…