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 file URL error on Windows #2

Merged
merged 3 commits into from
Jul 30, 2024
Merged

Conversation

ericx20
Copy link
Contributor

@ericx20 ericx20 commented Jul 27, 2024

On Windows, create-cubing-app errors out. Here is an example:

PS C:\Users\ericx> npm create --yes cubing-app@latest my-cubing-project
---------------------------------
Creating a cubing project in the following folder:
my-cubing-project

node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^

[Error: ENOENT: no such file or directory, lstat 'C:\C:\Users\ericx\AppData\Local\npm-cache\_npx\8f9f419572216059\node_modules\create-cubing-app\app-template'] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'lstat',
  path: 'C:\\C:\\Users\\ericx\\AppData\\Local\\npm-cache\\_npx\\8f9f419572216059\\node_modules\\create-cubing-app\\app-template'
}

Line 69 of bin/create-cubing-app.js throws an error because of the leading slash on appTemplatePath.
For some reason on Windows, that makes Node fs.cp access a bad path with a double C:\. On Linux the leading slash works fine.

Solution is to use Node url.fileURLToPath to ensure the URL is a proper absolute path on different platforms. On Windows it removes the leading slash like so:

  • before: '/C:/Users/ericx/Documents/dev/create-cubing-app/app-template'
  • after: 'C:\\Users\\ericx\\Documents\\dev\\create-cubing-app\\app-template'

@lgarron
Copy link
Member

lgarron commented Jul 27, 2024

I'm happy to support Windows, but I don't have an easy way to test for it. Could I ask you to also add a GitHub action on Windows testing that project creation works, as well as a build in the created folder? That would catch any regressions.

@ericx20
Copy link
Contributor Author

ericx20 commented Jul 28, 2024

Good idea! I've added an action for that. Let me know if you need any further changes.

@lgarron lgarron merged commit 9b09043 into cubing:main Jul 30, 2024
1 check passed
@lgarron
Copy link
Member

lgarron commented Jul 30, 2024

Thanks! 😊

lgarron added a commit that referenced this pull request Jul 31, 2024
Release notes:

- Windows compatibility. (Thanks to @ericx20 at #2)
@ericx20 ericx20 deleted the fix-windows-url branch July 31, 2024 00:44
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.

2 participants