Skip to content

[Bug]: __dirname is broken when using syntax: 'es2021' #236

Closed
@chenjiahan

Description

@chenjiahan

Version

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.62 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 129.0.6668.59
    Safari: 17.6

Details

Input:

console.log(__dirname);

Without syntax

  • config:
import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [{ format: 'esm' }],
  output: {
    target: 'node',
  },
});
  • output:
import { fileURLToPath as __webpack_fileURLToPath__ } from "url";
import { dirname as __webpack_dirname__ } from "path";
var __dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
console.log(__dirname);

With syntax

  • config:
import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [{ format: 'esm', syntax: 'es2021' }],
  output: {
    target: 'node',
  },
});
  • output:
console.log('/');

Reproduce link

web-infra-dev/rsbuild#3563

Reproduce Steps

See web-infra-dev/rsbuild#3563

create-rsbuild is broken after adding syntax: 'es2021'.

Metadata

Metadata

Assignees

Labels

🐞 bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions