You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code being built is in a subdirectory and refers to __dirname
The RsPack build is run on Windows via the Windows cmd command 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!)
Thank you! 🙏 As an additional observation, noticed that this only seems to affect node: { __dirname: true }. node: { __filename: true } appears to work as expected in RsPack (escapes the backslash path separators).
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__dirname
cmd
command promptthen 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
node: { __dirname: true }
in the RsPack configuration.__dirname
in a subdirectory file in the code being built (for example, like in the reproduce repo).cmd
command promptWhat 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#L15webpack 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#L10Desired result
RsPack and webpack build results match in terms of
__dirname
: both produce escaped output, e.g.src\\foo\\bar\\baz
The text was updated successfully, but these errors were encountered: