-
-
Notifications
You must be signed in to change notification settings - Fork 782
Description
System Info
System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 5.78 GB / 15.82 GB
Binaries:
Node: 20.18.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.12.2 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Chrome: 129.0.6668.101
Edge: Spartan (44.19041.1266.0), Chromium (129.0.2792.89)
Internet Explorer: 11.0.19041.1566
Details
Note: This issue only reproduces when building on Windows, as Windows uses the \ path separator.
If
node: { __dirname: true }(webpack documentation) is used in the RsPack config and- The code being built is in a subdirectory and refers to
__dirname - The RsPack build is run on Windows via the Windows
cmdcommand prompt
then RsPack output contains unescaped \ characters (e.g. __dirname: ${'src\foo\bar\baz'}), resulting in an unexpected string and not matching the webpack output (e.g. var __dirname = "src\\foo\\bar\\baz"; ... `__dirname: ${__dirname}).
(Thank you for your awesome work on this project 🙏❤ . Hope this report proves to be useful!)
Reproduce link
https://github.com/lauriharpf/rspack-node-dirname/tree/main
Reproduce Steps
- Use
node: { __dirname: true }in the RsPack configuration. - Refer to
__dirnamein a subdirectory file in the code being built (for example, like in the reproduce repo). - Run the build on Windows via the
cmdcommand prompt
What happens
RsPack does not escape the \-separator, output is e.g. src\foo\bar\baz. See https://github.com/lauriharpf/rspack-node-dirname/blob/main/rspack-dist/src_foo_bar_baz_render_js.js#L15
webpack escapes the \-separator, output is e.g. src\\foo\\bar\\baz. See https://github.com/lauriharpf/rspack-node-dirname/blob/main/webpack-dist/src_foo_bar_baz_render_js.js#L10
Desired result
RsPack and webpack build results match in terms of __dirname: both produce escaped output, e.g. src\\foo\\bar\\baz

