TypeError [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader (Windows drive letter backslash) – Node.js ERR_UNSUPPORTED_ESM_URL_SCHEME

ERR_UNSUPPORTED_ESM_URL_SCHEME

Su Windows, passare un percorso assoluto con backslash ('C:\path\file.js') a un'istruzione di importazione ESM fallisce perché il loader richiede uno schema URL ('file:///C:/path/file.js') o l'uso di 'pathToFileURL()' del modulo url nativo.

Cosa significa questo errore?

Su Windows, passare un percorso assoluto con backslash ('C:\path\file.js') a un'istruzione di importazione ESM fallisce perché il loader richiede uno schema URL ('file:///C:/path/file.js') o l'uso di 'pathToFileURL()' del modulo url nativo.

Messaggio originale

TypeError [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader (Windows drive letter backslash)

Contesto e parole chiave

Alias

  • ERR_UNSUPPORTED_ESM_URL_SCHEME Node.js Windows

Messaggi alternativi

  • schema URL non supportato lettera di unità Windows in import ESM

Prodotti

  • Node.js Runtime (v18 LTS, v20 LTS, v22 LTS, v24)

Piattaforme

  • Linux
  • macOS
  • Windows

Parole chiave

  • errore-nodejs-err-unsupported-esm-url-scheme
  • javascript-backend
  • Moduli e CommonJS ed ESM
  • node
  • nodejs
  • nodejs.moduli.err-unsupported-esm-url-scheme

Cause possibili

Causa tecnica per Errore Node.js: ERR_UNSUPPORTED_ESM_URL_SCHEME (Percorsi con Backslash su Windows)

Su Windows, passare un percorso assoluto con backslash ('C:\path\file.js') a un'istruzione di importazione ESM fallisce perché il loader richiede uno schema URL ('file:///C:/path/file.js') o l'uso di 'pathToFileURL()' del modulo url nativo.

molto comune

Diagnosi

Diagnostica di runtime o stack trace per Errore Node.js: ERR_UNSUPPORTED_ESM_URL_SCHEME (Percorsi con Backslash su Windows)

Eseguire Node.js con i flag diagnostici (--trace-warnings --trace-uncaught) per visualizzare l'origine dettagliata dell'eccezione.

Come leggere il risultato. Evidenzia il modulo esatto, la riga e lo stack trace della chiamata asincrona in errore.

terminal
node --trace-warnings --trace-uncaught app.js

Risoluzione

Risoluzione standard per Errore Node.js: ERR_UNSUPPORTED_ESM_URL_SCHEME (Percorsi con Backslash su Windows)

Difficoltà: mediaRischio: basso

Applicare la correzione al codice sorgente Node.js o alla configurazione del package.json.

  1. Ispezionare la riga evidenziata dal codice di errore o stack trace
  2. Aggiornare la sintassi di import/export, il controllo dei socket o la gestione della memoria
  3. Riavviare il processo Node.js o il demone di produzione (PM2/systemd) per verificare la stabilità
terminal
node app.js

Domande frequenti

Come risolvere l'errore Errore Node.js: ERR_UNSUPPORTED_ESM_URL_SCHEME (Percorsi con Backslash su Windows) in Node.js?

Su Windows, passare un percorso assoluto con backslash ('C:\path\file.js') a un'istruzione di importazione ESM fallisce perché il loader richiede uno schema URL ('file:///C:/path/file.js') o l'uso di 'pathToFileURL()' del modulo url nativo.

Approfondimenti

Schede correlate