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

Can't import jsonc as config file #9055

Closed
truongan07 opened this issue Feb 22, 2024 · 4 comments
Closed

Can't import jsonc as config file #9055

truongan07 opened this issue Feb 22, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@truongan07
Copy link

What version of Bun is running?

1.0.27+c34bbb2e3

What platform is your computer?

Linux 6.3.6-arch1-1 x86_64 unknown

What steps can reproduce the bug?

Bun.sh can't read jsonc file from import

const jsonc = await import('./services.config.jsonc');

console.log('jsonc: ', jsonc);

What is the expected behavior?

return an object as :

{
 a: "a",
 b: "b"
}

What do you see instead?

Module {
  default: "./services.config.jsonc",
}

Additional information

I want to use config file in jsonc format for comments

@truongan07 truongan07 added the bug Something isn't working label Feb 22, 2024
@Jarred-Sumner
Copy link
Collaborator

hmm this is supposed to work but i don't think we have tests for it

@truongan07
Copy link
Author

@Jarred-Sumner Hi my friend, jsonc is very useful when used to create a config file. We need more comments to describe keys.

@Delapouite
Copy link

Here is the relevant part in fs.zig: https://github.com/oven-sh/bun/blob/main/src/fs.zig#L1668-L1675

    pub fn isJSONCFile(this: *const Path) bool {
        const str = this.name.filename;
        if (!(strings.hasPrefixComptime(str, "tsconfig.") or strings.hasPrefixComptime(str, "jsconfig."))) {
            return false;
        }

        return strings.hasSuffixComptime(str, ".json");
    }

So

tsconfig.json

{
  // comment
  "foo": "bar"
}

index.js

const jsonc = await import('./tsconfig.json');

console.log('jsonc: ', jsonc);
bun run index.js
jsonc:  Module {
  default: {
    foo: "bar",
  },
  foo: "bar",
}

@truongan07
Copy link
Author

resolved in v.1.1.5

import jsonc from './config/services.config.jsonc' with { type: 'text' };

Thank you support

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

3 participants