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

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

Open
kainstar opened this issue Nov 9, 2024 · 2 comments
Open

Comments

@kainstar
Copy link

kainstar commented Nov 9, 2024

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

@kainstar kainstar added the 🐞 bug Something isn't working label Nov 9, 2024
@chenjiahan
Copy link
Member

Currently import.meta.dirname is supported in the rsbuild.config.mjs file.

For rsbuild.config.ts, we need to upgrade jiti to add support for import.meta.dirname, I will try to do the upgrade this week. 😄

@chenjiahan chenjiahan self-assigned this Nov 12, 2024
@chenjiahan
Copy link
Member

I have just discovered that we cannot upgrade to jiti v2 at the moment because postcss-load-config is using jiti v1.

@chenjiahan chenjiahan added 💡 feature and removed 🐞 bug Something isn't working labels Nov 12, 2024
@chenjiahan chenjiahan changed the title [Bug]: Can not use import.meta.dirname in rsbuild.config.ts [Feature]: Support for using import.meta.dirname in rsbuild.config.ts Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants