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

Runtime error after update from 1.5.0 to 2.0.4 #34

Closed
NLueg opened this issue Mar 4, 2024 · 5 comments
Closed

Runtime error after update from 1.5.0 to 2.0.4 #34

NLueg opened this issue Mar 4, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@NLueg
Copy link

NLueg commented Mar 4, 2024

Hi there, we recently tried to update to 2.0.4. TypeScript is actually happy about the changes but we receive an issue during runtime:

TypeError: Cannot read properties of undefined (reading 'clientCredentials')
    at getClientCredentials (C:\Users\NICLUEG\GitHub\customer-search-service\src\vehicle\vehicle-kdm\vehicle-kdm.service.ts:13:35)
    at VehicleKdmService.getKdmInfo (C:\Users\NICLUEG\GitHub\customer-search-service\src\vehicle\vehicle-kdm\vehicle-kdm.service.ts:54:17) 
    at VehicleKdmController.getKdmInfo (C:\Users\NICLUEG\GitHub\customer-search-service\src\vehicle\vehicle-kdm\vehicle-kdm-controller.ts:22:24)
    at C:\Users\NICLUEG\GitHub\customer-search-service\node_modules\@nestjs\core\router\router-execution-context.js:38:29
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at C:\Users\NICLUEG\GitHub\customer-search-service\node_modules\@nestjs\core\router\router-execution-context.js:46:28
    at C:\Users\NICLUEG\GitHub\customer-search-service\node_modules\@nestjs\core\router\router-proxy.js:9:17

We use this code for retrieving the clientCredentials:

import oauth from 'axios-oauth-client';
import * as axios from 'axios';

async function getClientCredentials() {
  Logger.debug('trying to get credentials');
  const tokenResult = await oauth.clientCredentials(
    axios.default.create(),
    process.env.OAUTH_URL,
    process.env.OAUTH_CLIENTID,
    process.env.OAUTH_CLIENTSECRET
  )('');
  return tokenResult;
}

This is our TSConfig:

{
  "compilerOptions": {
    "skipLibCheck": true,
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES2021",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "resolveJsonModule": true
  },
  "exclude": ["node_modules", "dist"],
  "rules": {
    "quotemark": [true, "single", "avoid-escape"]
  }
}

Do you have an idea what could be the issue?

@compwright
Copy link
Owner

Sorry, can't help you. The error is happening in your code, not in this library.

@compwright compwright added the invalid This doesn't seem right label Apr 28, 2024
@NLueg
Copy link
Author

NLueg commented Apr 29, 2024

@compwright I actually don't think that. It just happens after the update and the error definitely says that oauth (from import oauth from 'axios-oauth-client') doesn't export the function clientCredentials

@compwright
Copy link
Owner

Sorry, I misunderstood your initial post. On further review, it does look like there is an issue with the export in the compiled .mjs version.

@compwright compwright reopened this Apr 29, 2024
@compwright compwright added bug Something isn't working and removed invalid This doesn't seem right labels Apr 29, 2024
@compwright
Copy link
Owner

Please upgrade to v2.2.0, and then change your import from this:

import oauth from 'axios-oauth-client';

To this:

import { clientCredentials } from 'axios-oauth-client';

@NLueg
Copy link
Author

NLueg commented Apr 29, 2024

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants