typescriptbrowserpuppeteer

TypeScript `error TS2503: Cannot find namespace 'browser'.`


Building Typescript crashes with the following error in @cliqz/adblocker:

node_modules/@cliqz/adblocker/dist/commonjs/request.d.ts:12:37 - error TS2503: Cannot find namespace 'browser'.

12 export type WebRequestTypeFirefox = browser.webRequest.ResourceType;

@cliqz/adblocker version is 1.30.0, node v20.15.1

My tsconfig.json

{
  "compilerOptions": {
    "target": "es2017",
    "outDir": "build",
    "rootDir": "src",
    "moduleResolution": "node",
    "module": "commonjs",
    "declaration": true,
    "inlineSourceMap": true,
    "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
    /* Additional Checks */
    "noUnusedLocals": true /* Report errors on unused locals. */,
    "noUnusedParameters": true /* Report errors on unused parameters. */,
    "noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
    "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
    /* Debugging Options */
    "traceResolution": false /* Report module resolution log messages. */,
    "listEmittedFiles": false /* Print names of generated files part of the compilation. */,
    "listFiles": false /* Print names of files part of the compilation. */,
    "pretty": true /* Stylize errors and messages using color and context. */,
    "lib": ["es2017", "dom"],
    "types": ["jest", "node", "puppeteer", "winston", "chrome"],
    "typeRoots": ["node_modules/@types", "src/types"]
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", "**/*.spec.ts", "__tests__"]
}

Solution

  • You need to install:

    npm install --save-dev @types/firefox-webext-browser
    

    And probably this one too:

    npm install --save-dev @types/chrome