Skip to content

Fails on Windows again #41

Closed
Closed

Description

@ntwilson

When running on Windows I get an error

Invalid module ".\file:\C:\Users\nathan.wilson\git<path to spec module>\index.js" is not a valid package name imported from C:\Users\nathan.wilson\git...\output\Test.Spec.Discovery\foreign.js
Stack trace:
(Just "TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module ".\file:\C:\Users\nathan.wilson\git\\index.js" is not a valid package name imported from C:\Users\nathan.wilson\git\...\output\Test.Spec.Discovery\foreign.js\n at parsePackageName (node:internal/modules/package_json_reader:224:11)\n at Object.getPackageJSONURL (node:internal/modules/package_json_reader:235:53)\n at packageResolve (node:internal/modules/esm/resolve:768:81)\n at moduleResolve (node:internal/modules/esm/resolve:858:18)\n at defaultResolve (node:internal/modules/esm/resolve:990:11)\n at #cachedDefaultResolve (node:internal/modules/esm/loader:735:20)\n at ModuleLoader.resolve (node:internal/modules/esm/loader:712:38)\n at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:310:38)\n at onImport.tracePromise.proto (node:internal/modules/esm/loader:663:36)\n at TracingChannel.tracePromise (node:diagnostics_channel:344:14)")

I asked Claude to fix it, and it suggested

-import { fileURLToPath } from 'url'
+import { fileURLToPath, pathToFileURL } from 'url'

...

    const modulePromises = fs
      .readdirSync(path.join(__dirname, '..'))
      .filter(directory => regex.test(directory))
      .map(name => {
+        const filePath = path.join(__dirname, '..', name, 'index.js')
        const fullPath = __onWindows
-          ? path.join('file://', __dirname, '..', name, 'index.js')
-          : path.join(__dirname, '..', name, 'index.js')
+          ? pathToFileURL(filePath).href
+          : filePath
        return import(fullPath).then(module =>
          module && typeof module.spec !== 'undefined' ? module.spec : null
        )
      })

And when I made this change to Test.Spec.Discovery/foreign.js, then it works again.
I'm guessing this is related to #30.

Would you accept a PR with the fix Claude suggested?

purescript-spec-discovery: 8.4.0
Node: 24.5.0 (A coworker reproduced on Node 22.16)
Windows: 11 Pro (10.0.26100 Build 26100)
PureScript: 0.15.15
Spago: 0.93.44

Activity

  1. CarstenKoenig commented on Sep 24, 2025

    @CarstenKoenig
    Contributor

    Hi,

    thanks for this update (did run into the same trouble).

    I think

    const fullPath = pathToFileURL(filePath, { "windows": __onWindows }).href
    

    or even

    const fullPath = pathToFileURL(filePath).href
    

    should work on both OS (thanks for the hint - I actually did not know this function).

  2. fsoikin commented on Oct 21, 2026

    @fsoikin
    Member

    Fixed via #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions