Skip to content

[Feature]: Support for using import.meta.dirname in rsbuild.config.ts #3931

@kainstar

Description

@kainstar

Version

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (2) x64 AMD EPYC
    Memory: 1.77 GB / 4.01 GB
    Container: Yes
    Shell: Unknown
  npmPackages:
    @rsbuild/core: ^0.7.9 => 0.7.9 
    @rsbuild/plugin-react: ^0.7.9 => 0.7.9

Details

I want to use import.meta.dirname API in rsbuild config file which is supportted in esm module since node v20.11.0

import { defineConfig } from "@rsbuild/core";
import { pluginReact } from "@rsbuild/plugin-react";

console.log(import.meta.dirname);

export default defineConfig({
  plugins: [pluginReact()],
});

but it will throw a SyntaxError:
Image

From the error stack, I learned that rsbuild loads the config file with jiti. After some attempts, I discovered that rsbuild precompiles an old version of jiti code which doesn't support import.meta.dirname in its distribution. This means I can't use methods like pnpm.overrides to change the installed jiti version, and only downgrade to fileURLToPath(import.meta.url)'s function call.

Is there any problem upgrading the jiti version? The import.meta.dirname API has supportted in v2.1.0 .It would be great if I could see this feature supported in the next version.
If not, could you explain why and if there's another way to use import.meta.dirname or plans to upgrade jiti?

Reproduce link

https://codesandbox.io/p/devbox/ts-config-esm-37nx8q

Reproduce Steps

run dev task

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions