it-gorillaz/configify

TypeError: value.matchAll is not a function

Closed this issue · 2 comments

When using numerical values in the application.yml file and restarting the application, getting the following error

database:
  uri: some_uri
  port: 27017

error log

[Nest] 26114  - 07/18/2024, 10:46:18 PM     LOG [NestFactory] Starting Nest application...
[Nest] 26114  - 07/18/2024, 10:46:18 PM   ERROR [ExceptionHandler] value.matchAll is not a function
TypeError: value.matchAll is not a function
    at Function.lastIndexOf (/Users/my-api/node_modules/@itgorillaz/configify/src/interpolation/variables.ts:98:38)
    at Function.interpolate (/Users/my-api/node_modules/@itgorillaz/configify/src/interpolation/variables.ts:59:47)
    at Function.expand (/Users/my-api/node_modules/@itgorillaz/configify/src/interpolation/variables.ts:43:49)
    at Function.forRootAsync (/Users/my-api/node_modules/@itgorillaz/configify/src/configify.module.ts:93:34)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
Waiting for the debugger to disconnect...

When i convert the number to a string like below, its working fine

database:
  uri: some_uri
  port: '27017'

What is the reason behind the error value.matchAll is not a function

Note: You need to restart the application to get the above error while using a numerical value

@sandeepsuvit thanks for reporting the error!

I was able to reproduce and indeed the yaml parser is converting the value to a number so it fails when interpolating the variables.

The fix will be in the next release.

@sandeepsuvit fixed on v1.2.3.
Note that since we assign the configuration to process.env the values are converted to string, it is a good idea to use the parse option if your config attribute is not a string, e.g.:

@Configuration
export class DatabaseConfiguration {
  @Value('database.host')
  host: string;

  @Value('database.port', { parse: parseInt })
  port: number;
}