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(payload): Passes correct path to import modules on Windows started with file:// #5919

Merged
merged 4 commits into from
Apr 19, 2024

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Apr 19, 2024

Description

TL;DR: There's a Discord thread with that issue https://discord.com/channels/967097582721572934/1225824784609316906/1227622673564041370
Here's what was wrong nodejs/node#31710
It's working fine for me with generate:types though. But when i'm trying to run a standalone script (from demo repo) - not, i'm getting this:

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:239:11)
    at defaultLoad (node:internal/modules/esm/load:130:3)
    at nextLoad (node:internal/modules/esm/hooks:866:28)
    at Z (file:///C:/Users/enjoy/work/payload/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/esm/index.mjs:5:1618)
    at nextLoad (node:internal/modules/esm/hooks:866:28)
    at Hooks.load (node:internal/modules/esm/hooks:449:26)
    at ModuleLoader.load (node:internal/modules/esm/loader:402:34)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:56)
    at new ModuleJob (node:internal/modules/esm/module_job:67:26)
    at #createModuleJob (node:internal/modules/esm/loader:297:17) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

I added to _community folder a script (probably should remove it), you can run it like this
pnpm tsx .\test\_community\standalone-script.ts
It should throw ValidationError email already exists, but it's fine. I tested it on a normal project (macOS and Windows) and it's working as expected.

  • I have read and understand the CONTRIBUTING.md document in this repository.

@r1tsuu r1tsuu changed the title fix(payload): Passes correct path to import functions started with file:// fix(payload): Passes correct path to import functions on Windows started with file:// Apr 19, 2024
@r1tsuu r1tsuu changed the title fix(payload): Passes correct path to import functions on Windows started with file:// fix(payload): Passes correct path to import modules on Windows started with file:// Apr 19, 2024
@paulpopus
Copy link
Contributor

Assigning to @DanRibbens since it looks like a windows thing

@DanRibbens
Copy link
Contributor

I tested this locally and it worked from the demo project, whereas before I was getting the same errors. Great work @r1tsuu!

@r1tsuu
Copy link
Member Author

r1tsuu commented Apr 19, 2024

I removed the script in tests and a bit updated variables assigning i think it's better looking now.

@DanRibbens
Copy link
Contributor

Awesome! I'll merge this once it gets through CI.

@denolfe denolfe merged commit 2729728 into payloadcms:beta Apr 19, 2024
25 of 26 checks passed
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.

4 participants