question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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, 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"
  • 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:closed
  • Created 6 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
develarcommented, Mar 24, 2017

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

0reactions
tiangolocommented, Mar 26, 2017

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot find module electron updater - Stack Overflow
NPM can run your application in debug (development) mode and in production mode, neither of which involve Electron Builder. Electron Builder ...
Read more >
electron-updater | Yarn - Package Manager
A complete solution to package and build a ready for distribution Electron, Proton Native app for macOS, Windows and Linux with “auto update”...
Read more >
Trying to switch to Typescript under Jovo v3 - Questions
I'm in the process of prepping my code to cut over to TypeScript. ... error TS2503: Cannot find namespace 'SocketIOClient'. 37 socket?: SocketIOClient....
Read more >
cannot find module 'assert' or its corresponding type ...
How to Solve cannot find module and its corresponding type declarations ... Unable to compile Typescript using mocha and visual Studio Code Debugger....
Read more >
electron-publish: Versions | Openbase
fix(app-builder-lib): export missing TS types by @indutny-signal in ... electron-updater throws "Cannot find namespace 'debug'" on TypeScript compile ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found