Moduli e CommonJS ed ESM
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
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 comuneDiagnosi
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.
node --trace-warnings --trace-uncaught app.jsRisoluzione
Risoluzione standard per Errore Node.js: ERR_UNSUPPORTED_ESM_URL_SCHEME (Percorsi con Backslash su Windows)
Applicare la correzione al codice sorgente Node.js o alla configurazione del package.json.
- Ispezionare la riga evidenziata dal codice di errore o stack trace
- Aggiornare la sintassi di import/export, il controllo dei socket o la gestione della memoria
- Riavviare il processo Node.js o il demone di produzione (PM2/systemd) per verificare la stabilità
node app.jsDomande 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
- Node.js Official Documentation / Node.js Errors Reference documentazione_ufficiale