Skip to content

Conversation

Vessel9817
Copy link

@Vessel9817 Vessel9817 commented Sep 22, 2025

Problem description

Suppose your project directory is C:\Users\username\myproject and the source map is trying to load index.js. After running the following snippet:

const filePath = `${process.cwd()}/${projectNameInput}/${source.substring(
  WEBPACK_SUBSTRING_INDEX,
)}`;

then filePath is set to C:\Users\username\myproject. This is because WEBPACK_SUBSTRING_INDEX is greater than the length of "index.js" (11 > 8), so source.substring(WEBPACK_SUBSTRING_INDEX) returns an empty string. In fact, WEBPACK_SUBSTRING_INDEX is completely arbitrary. The program continues as normal, expecting that filePath is a file path, and tries to write to said file. Except, it's a directory, so fs.writeFileSync fails:

Error: EISDIR: illegal operation on a directory, open 'C:\Users\username\myproject\

Changes

  • Removed WEBPACK_SUBSTRING_INDEX and subsequent substring call
  • Added error detection to fail with a clearer error message
  • Updated dependency lock files*

*Note that I use npm rather than Yarn, so if the project runs without these changes, then feel free to discard this particular change.

Support

Versions tested:

  • Node v24.0.0
  • npm version 11.6.0

Signed-off-by: Vessel9817 <151808241+Vessel9817@users.noreply.github.com>
Signed-off-by: Vessel9817 <151808241+Vessel9817@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant