Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Migration script error: ERR_UNSUPPORTED_ESM_URL_SCHEME #38

Closed
AdisonCavani opened this issue Apr 27, 2024 · 9 comments
Closed

Migration script error: ERR_UNSUPPORTED_ESM_URL_SCHEME #38

AdisonCavani opened this issue Apr 27, 2024 · 9 comments

Comments

@AdisonCavani
Copy link

Environment

package.json:

"dependencies": {
    "@sentry/nextjs": "8.0.0-beta.4",
    "next": "14.2.3",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.3",
    "typescript": "^5"
  }
node -v: v21.7.1

Steps to Reproduce

npx @sentry/migr8@latest

Expected Result

Successful migration

Actual Result

●  Detected SDK: @sentry/nextjs
node:internal/modules/esm/load:239
    throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
          ^

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 ModuleLoader.load (node:internal/modules/esm/loader:403:13)
    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)
    at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:254:34)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:235:17)
    at async ModuleLoader.import (node:internal/modules/esm/loader:322:23) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Node.js v21.7.1
@Lms24
Copy link
Member

Lms24 commented May 13, 2024

HI @AdisonCavani sorry for the late reply, we only recently touched this tool again 😬

Is this still an issue today? We're currently releasing version 8.0.0 of the SDKs which changed a lot around ESM and package.json exports so chances are that whatever caused this, is already fixed.

@leviwolfe
Copy link

Just tried and got the same error, using Node 22.1.0 on Windows. I'm guessing you are dynamically loading a module with a path like "c:\somewhere\on\disk.js" but it needs to start with a "file://" scheme to work. Using pathToFileURL() might help?

>node -v
v22.1.0

>npx @sentry/migr8@latest
┌  Welcome to sentry-migr8!
│
◇   ───────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                          │
│  This command line tool will update your Sentry JavaScript setup to the latest version.  │
│                                                                                          │
│    We will guide you through the process step by step.                                   │
│    This tool collectes anonymous telemetry data and sends it to Sentry.                  │
│    You can disable this by passing the --disableTelemetry option.                        │
│                                                                                          │
├──────────────────────────────────────────────────────────────────────────────────────────╯
│
◇   ───────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                  │
│  We will run transforms on files matching the following pattern, ignoring any gitignored files:  │
│    **/*.{js,jsx,ts,tsx,cjs,cts,mjs,mts,vue,svelte}                                               │
│    (You can change this by specifying the --filePatterns option)                                 │
│                                                                                                  │
├──────────────────────────────────────────────────────────────────────────────────────────────────╯
│
●  Detected SDK: @sentry/sveltekit
node:internal/modules/esm/load:249
    throw new ERR_UNSUPPORTED_ESM_URL_SCHEME(parsed, schemes);
          ^

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:249:11)
    at defaultLoad (node:internal/modules/esm/load:130:3)
    at ModuleLoader.load (node:internal/modules/esm/loader:554:13)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:435:56)
    at new ModuleJob (node:internal/modules/esm/module_job:76:27)
    at #createModuleJob (node:internal/modules/esm/loader:448:17)
    at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:260:34)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:17)
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:23) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Node.js v22.1.0

@oddeirik
Copy link

Same issue here. Windows 11, Node v20.13.1, npm 10.7.0. Runs fine under WSL2 with Ubuntu 22.04 and the same Node/npm versions.

@Lms24
Copy link
Member

Lms24 commented May 14, 2024

thanks for the hints, looking into this in a sec!

@Zandor300
Copy link

Tried to be smart and run this tool in a Docker container to get around the error of this issue using the following in Powershell:

docker run --rm -v ${pwd}:/app -w /app node:20 npx @sentry/migr8@latest

But received the following error for version 0.2.0:

Error of the command above
node:tty:93
    throw new ERR_TTY_INIT_FAILED(ctx);
          ^

SystemError [ERR_TTY_INIT_FAILED]: TTY initialization failed: uv_tty_init returned EINVAL (invalid argument)
    at new WriteStream (node:tty:93:11)
    at xD.prompt (file:///root/.npm/_npx/daeb407631c9d9de/node_modules/@clack/core/dist/index.mjs:9:818)
    at se (file:///root/.npm/_npx/daeb407631c9d9de/node_modules/@clack/prompts/dist/index.mjs:22:7)
    at checkGitStatus (file:///root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/migr8/src/utils/clackUtils.js:66:7)
    at file:///root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/migr8/src/utils/telemetry.js:105:56
    at /root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/core/cjs/tracing/trace.js:54:11
    at Object.handleCallbackErrors (/root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/core/cjs/utils/handleCallbackErrors.js:26:26)
    at trace (/root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/core/cjs/tracing/trace.js:53:31)
    at traceStep (file:///root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/migr8/src/utils/telemetry.js:105:10)
    at runWithTelementry (file:///root/.npm/_npx/daeb407631c9d9de/node_modules/@sentry/migr8/src/run.js:63:11) {
  code: 'ERR_TTY_INIT_FAILED',
  info: {
    errno: -22,
    code: 'EINVAL',
    message: 'invalid argument',
    syscall: 'uv_tty_init'
  },
  errno: [Getter/Setter],
  syscall: [Getter/Setter]
}

@Lms24
Copy link
Member

Lms24 commented May 15, 2024

Can anyone confirm that ● Detected SDK: <sdk> is the last log you see?

If so, I think I found the culprit. @AdisonCavani your suspicion RE importing a module with wrong paths is correct. We currently hardcoded a \ in there. I wonder if we really need a file URL but I'll experiment with this a big.

@Lms24
Copy link
Member

Lms24 commented May 15, 2024

to everyone following this issue (gonna tag @AdisonCavani and @leviwolfe): We just released a new version. If you run npx @sentry/migr8@latest again, does it work now for you?

Given you're on windows, there seems to be a known issue with terminals that use Git Bash/MINGW and the library we use for the input prompts in migr8. So I recommend using a terminal that doesn't use the Git Bash shell to run migr8.

Hoping this works 🤞
(Also apologies for the turnaround time on this one; Sentry is a MacOS only company and I need to get home to my windows PC to test this properly lol)

@Lms24
Copy link
Member

Lms24 commented May 16, 2024

I ran migr8 yesterday on my windows PC with PowerShell. It worked. I'm gonna close this issue for the moment. Please feel free to ping me if the issue is not fixed for anyone, thanks :)

@Lms24 Lms24 closed this as completed May 16, 2024
@oddeirik
Copy link

Worked with Powershell (in Windows Terminal) on my end as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants