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

fix(npm index.js): convert file url to actual path #959

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

jstarpl
Copy link
Contributor

@jstarpl jstarpl commented Mar 14, 2024

This PR fixes an issue that happens, at least on Windows, when the user has a space character in their Username.

The symptom:

> ssc init
node:internal/modules/cjs/loader:1147
  throw err;
  ^

Error: Cannot find module 'C:\Users\Jan%20Starzak\AppData\Roaming\nvm\v20.11.1\node_modules\@socketsupply\socket\node_modules\@socketsupply\socket-win32-x64\bin\ssc-platform.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

On Windows (but maybe on other platforms too), file URLs can contain spaces which will be encoded as %20. When treating these URL strings as paths, the OS will claim it doesn't recognize these paths because it won't URL-decode them automatically.
The ENOENT here is caused by the un-url'ed cwd property passed into spawn.
Therefore, the import.meta.url needs to be converted to an actual filePath before all the other path processing can be done to it.

Certainly on Windows (but maybe on other platforms too), file URLs can contain spaces which will be encoded as %20. When then treating these strings as paths, the OS will claim it doesn't recognize these paths because it won't URL-decode them automatically. Therefore, the `import.meta.url` needs to be converted to an actual filePath before all the other path processing can be done on it.
@jwerle jwerle added npm An issue, task, discussion, or pull request related to the NPM modules bug Something isn't working labels Mar 14, 2024
@jwerle jwerle merged commit c35151a into socketsupply:master Mar 15, 2024
@jstarpl jstarpl deleted the patch-1 branch March 16, 2024 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working npm An issue, task, discussion, or pull request related to the NPM modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants