Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error TS7016: Could not find a declaration file for module 'request'. #657

Closed
rdok opened this issue Dec 5, 2023 · 4 comments
Closed

error TS7016: Could not find a declaration file for module 'request'. #657

rdok opened this issue Dec 5, 2023 · 4 comments
Assignees

Comments

@rdok
Copy link

rdok commented Dec 5, 2023

SDK Version: 4.37.0

Describe the bug

Fails to compile in a TypeScript based project. This issue also includes a temporarily solution.

Actual error

$  npm run build

> [email protected] prebuild
> rm -rf dist/


> [email protected] build
> rm -rf dist && tsc -p .

node_modules/xero-node/dist/gen/model/accounting/models.d.ts:134:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

134 import localVarRequest = require('request');
                                     ~~~~~~~~~

node_modules/xero-node/dist/gen/model/appstore/models.d.ts:11:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

11 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/assets/models.d.ts:13:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

13 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/bankfeeds/models.d.ts:13:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

13 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/files/models.d.ts:10:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

10 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/finance/models.d.ts:55:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

55 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/payroll-au/models.d.ts:89:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

89 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/payroll-nz/models.d.ts:100:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

100 import localVarRequest = require('request');
                                     ~~~~~~~~~

node_modules/xero-node/dist/gen/model/payroll-uk/models.d.ts:91:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

91 import localVarRequest = require('request');
                                    ~~~~~~~~~

node_modules/xero-node/dist/gen/model/projects/models.d.ts:19:34 - error TS7016: Could not find a declaration file for module 'request'. '/home/services/acme/node_modules/request/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/request` if it exists or add a new declaration (.d.ts) file containing `declare module 'request';`

19 import localVarRequest = require('request');
                                    ~~~~~~~~~


Found 10 errors in 10 files.

Errors  Files
     1  node_modules/xero-node/dist/gen/model/accounting/models.d.ts:134
     1  node_modules/xero-node/dist/gen/model/appstore/models.d.ts:11
     1  node_modules/xero-node/dist/gen/model/assets/models.d.ts:13
     1  node_modules/xero-node/dist/gen/model/bankfeeds/models.d.ts:13
     1  node_modules/xero-node/dist/gen/model/files/models.d.ts:10
     1  node_modules/xero-node/dist/gen/model/finance/models.d.ts:55
     1  node_modules/xero-node/dist/gen/model/payroll-au/models.d.ts:89
     1  node_modules/xero-node/dist/gen/model/payroll-nz/models.d.ts:100
     1  node_modules/xero-node/dist/gen/model/payroll-uk/models.d.ts:91
     1  node_modules/xero-node/dist/gen/model/projects/models.d.ts:19

Temporarily solution

If you are encountering issues related to the 'request' module and its types, using declare module 'request'; is a way to tell TypeScript that the module will exist at runtime, and it helps TypeScript understand that the types are available externally. This declaration is often used with third-party libraries or modules that don't have TypeScript typings included.

ignore-types.d.ts. Put this file either in the root directory, or inside a directory you're implicitly including.

declare module "request" {
  export interface Options {}
}

To Reproduce

Code

import { logInfo } from "../lib/utils";
import { XeroClient } from "xero-node";

async function handler(): Promise<void> {
  logInfo("log xero connections");
  const xero = new XeroClient({
    clientId: "****************",
    clientSecret: "******************",
    grantType: "client_credentials",
  });

  await xero.getClientCredentialsToken();

  const contacts = await xero.accountingApi.getContacts("");

  logInfo("Contacts: ", contacts);
}

export { handler };
tsconfig.json
{
  "compilerOptions": {
    "outDir": "dist",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "target": "ES2018",
    "module": "commonjs",
    "lib": ["es2018", "ES6", "dom"],
    "declaration": false,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "strictPropertyInitialization": false,
    "typeRoots": ["./node_modules/@types"],
    "plugins": [
      {
        "transform": "ts-auto-mock/transformer",
        "cacheBetweenTests": false,
        "features": ["random"]
      }
    ]
  },
  "include": ["handlers", "lib", "dev"],
  "exclude": [
    "node_modules",
    "cicd-authorisation",
    ".aws-sam",
    ".github",
    "dist"
  ],
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true
}
TypeScript version:

At the time of this writing, 5 Dec 2023, the xero-node is using 3rd major version, whereas this use case scenario is using 4th.

    "ttypescript": "1.5.15",
    "typescript": "4.7.4"

Expected behavior

No compilation errors.

Copy link

github-actions bot commented Dec 5, 2023

PETOSS-372

Copy link

github-actions bot commented Dec 5, 2023

Thanks for raising an issue, a ticket has been created to track your request

@sangeet-joy-tw
Copy link
Contributor

hey @rdok

please use the latest version v5.0.1 we have got rid off request module altogether.

let us know.

@sangeet-joy-tw sangeet-joy-tw self-assigned this Feb 8, 2024
@sangeet-joy-tw
Copy link
Contributor

request module has been replaced with axios. please use the latest versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants