node-config
node-config copied to clipboard
Support Bun + Typescript
Is your feature request related to a problem? Please describe. Does node-config support Bun? If not, any plan to support it? I'm not sure if this is a bug or lack of feature, I saw in one old issue people mentioned some failure while using node-config in Bun, but I suspect it's not in TS.
Describe the solution you'd like
I'd like to use node-config in Bun in TS. The current codebase works flawlessly with node-config in TS in Node. Migrating to Bun, it fails, complaining that it couldn't find ts-node in node_modules. (Looking at the code, this is not surprising since the parser for .ts files is indeed ts-node.)
Describe alternatives you've considered Right now I converted all files to JSON, but the default file contains some logic (e.g. reading secrets from AWS SecretManager) which can't be converted to JSON. Converting it to JS does seem to be working. But it's a bit off to have a single JS file in a fully TS codebase.
Please tell us about your environment:
- node-config version: 3.3.12
- node-version: #N/A
- bun-version: 1.1.18
Thanks.
I have not used Bun, but my guess is it'll work if you add ts-node to your package.json dependencies.
By default, node-config only loads a couple of parsers - JSON and JSON5. Every other parser has to be specified as a dependency in your package.json file. This is so every app doesn't download every parser that has ever been integrated.
There's a short mention of this in the docs, but documentation is for wimps ;)
Right, but that's kinda the point; if people use Bun then they don't have Node and (I'm guessing that) ts-node is not an option for them. So the idea is to use Bun instead of ts-node as a Parser. (I'm not sure if ts-node can utilize Bun instead of Node.)
Does that make sense?
None of this makes sense. If you're not using node.js for node-config, you're on your own.
that seems to be more a bun issue than a lib issue.
I also use bun but my config files are .js indeed.
Maybe this could be fixed by overriding the Parser.tsParser with Parser.jsParser in your code?
You can check process.versions.bun to know if you're running bun or not.
The bun documentation claims it supports ts files natively.
https://github.com/oven-sh/bun/blob/main/docs/runtime/typescript.md
@akefirad is talking about: https://github.com/node-config/node-config/blob/4d7fac6104a7e984557894e7edf2077890509c6a/parser.js#L71
Node 23 supports ts
Node 22:
require.extensions [Object: null prototype] { '.js': [Function (anonymous)], '.json': [Function (anonymous)], '.node': [Function (anonymous)] }
Node 23
require.extensions [Object: null prototype] { '.js': [Function (anonymous)], '.json': [Function (anonymous)], '.node': [Function (anonymous)], '.cts': [Function: loadCTS], '.ts': [Function: loadTS], '.mts': [Function: loadMTS] }
Bun 1.2:
require.extensions { '.js': true, '.json': true, '.node': true }
So Bun needs a bug report to fix this.
Simplest solution if you know you're working in Bun might be to
require.extensions['.ts'] = true
https://github.com/oven-sh/bun/pull/18478
I'm narrowing the scope of this to specifically consider Bun, and closing it as a bug on Bun's side that's getting resolved as it gains support for require.extensions
The linked bun ticket is now marked as closed, fixed.