Skip to content

Fails on Windows again #41

@ntwilson

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

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