HubSpot Library in Typescript and esModuleInterop

SOLVE
PCarlson
Participant

In case it helps someone else, I was getting many errors running tsc with the hubspot nodejs library like:

 

node_modules/@hubspot/api-client/lib/codegen/cms/audit_logs/api/defaultApi.d.ts:13:8 - error TS1192: Module '"http"' has no default export.

13 import http from 'http';

and

./node_modules/@hubspot/api-client/lib/codegen/cms/audit_logs/model/models.d.ts:7:8 - error TS1259: Module '"/home/philc/node_projects/fut-skills/hubspot/node_modules/@types/request/index"' can only be default-imported using the 'esModuleInterop' flag

 

I was able to resolve this by modifying my tsconfig.json file to add the compiler option esModuleInterop so it looked like this:

 

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "strict": true,
    "noUnusedLocals": true,
    "esModuleInterop": true,
  },
  "include": [
    "app.ts",
    "config.ts",
    "types.ts",
    "src/**/*",
    "lib/**/*"
  ],
  "exclude": ["./node_modules"]
}

 

Phil

1 Accepted solution

Accepted Solutions
PCarlson
Solution
Participant

I'm just posting a simple reply so I can mark this as solved.

 

The solution to esModuleInterop errors reported by tsc for the HubSpot API library files is to add "esModuleInterop": true to tsconfig.json under the "compilerOptions": block. See the original post for sample content.

 

Phil

 

 

View solution in original post

2 Replies 2
dennisedson
Community Manager

@PCarlson 

Thank you for adding this for others to see!

Thanks,

Dennis



Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
PCarlson
Solution
Participant

I'm just posting a simple reply so I can mark this as solved.

 

The solution to esModuleInterop errors reported by tsc for the HubSpot API library files is to add "esModuleInterop": true to tsconfig.json under the "compilerOptions": block. See the original post for sample content.

 

Phil

 

 

View solution in original post