theoephraim / node-google-spreadsheet

Google Sheets API wrapper for Javascript / Typescript
https://theoephraim.github.io/node-google-spreadsheet
The Unlicense
2.34k stars 390 forks source link

Reference error - Cannot find module 'google-auth-library/build/src/auth/oauth2client' #677

Open michael-rivera-florencehc-com opened 10 months ago

michael-rivera-florencehc-com commented 10 months ago

Still have the same issue documented here - https://github.com/theoephraim/node-google-spreadsheet/issues/654

When using the following package.json

"dependencies": { "@aws-sdk/client-iam": "^3.414.0", "@aws-sdk/client-sqs": "^3.414.0", "@aws-sdk/client-ssm": "^3.414.0", "@aws-sdk/types": "^3.413.0", "@florencehealthcare/fhc-api": "^2.0.2", "@florencehealthcare/florence-api": "^0.0.10", "axios": "^1.5.0", "csv": "^6.3.3", "dotenv": "^16.3.1", "google-auth-library": "^8.8.0", "google-spreadsheet": "^4.1.0", "json2csv": "^5.0.7", "mongodb": "^6.1.0", "p-map": "^6.0.0" }, "devDependencies": { "@types/google-spreadsheet": "^3.3.2", "@types/lodash": "^4.14.198", "@types/node": "^20.6.3", "@types/p-map": "^2.0.0", "typescript": "^5.2.2" }

Then running tsc, the following error is achieved.

`node_modules/google-spreadsheet/dist/index.d.ts:5:25 - error TS2307: Cannot find module 'google-auth-library/build/src/auth/oauth2client' or its corresponding type declarations.

5 import { Headers } from 'google-auth-library/build/src/auth/oauth2client';



Found 1 error in node_modules/google-spreadsheet/dist/index.d.ts:5`

I have the following tsconfig.json file

{ "compilerOptions": { "lib": ["es2020"], "module": "node16", "esModuleInterop": true, "target": "ES2020", "moduleResolution": "node16", "resolveJsonModule": true, "sourceMap": true, "checkJs": false, "outDir": "dist", "types": ["node"] }, "include": ["./**/*.ts"], "exclude": ["node_modules", "dist"] }

For the file referenced, if I change line 5 from this
import { Headers } from 'google-auth-library/build/src/auth/oauth2client';
to this
import { Headers } from 'google-auth-library/build/src/auth/oauth2client.js';

It works

Updating the latest version did not help. Still the same error. Downgrading to 8.8.0 has the same effect
theoephraim commented 10 months ago

ah the joy of dealing with typescript and file paths... This is not really an issue with this module so much as an incompatibility with your build/config setup. Although there are likely ways to make the built code a bit more robust... Particularly migrating this project's build set up to tsup should help as it will spit out a single dist file. But not sure when I will get to that! If I find some time, I may be able to try to recreate this setup and figure out the resolution. I suspect it involves changing moduleResolution setting in your tsconfig?

oshliaer commented 8 months ago

It depends on the compilation settings. Try downgrading the JS version for the build.

Another way - if you sure - just add "skipLibCheck": true to compilerOptions