HubSpot Library in Typescript and esModuleInterop

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

@PCarlson

Thank you for adding this for others to see!

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

Hi,

Sorry to say that that workaround does not solve the problem for everyone. Library authors should not use esModuleInterop: true as you are forcing consumers of your package to change their tsconfig.
Please fix this

Thx