Dynamic import does not show location of SyntaxError
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
// syntax-error.mjs
console.log([
'str1'
'str2'
]);
Perform a dynamic import with node -e "import('./syntax-error.mjs').catch(console.error)", the output does not help identify the error and could be seen by users as if node.js itself had a SyntaxError:
SyntaxError: Unexpected string
at Loader.moduleStrategy (internal/modules/esm/translators.js:83:18)
at async link (internal/modules/esm/module_job.js:37:21)
Now create and run a loader.mjs script:
import './syntax.mjs';
Running loader.mjs produces useful output:
file:///usr/src/npm/failures/syntax-error.mjs:3
'str2'
^^^^^^
SyntaxError: Unexpected string
at Loader.moduleStrategy (internal/modules/esm/translators.js:83:18)
I was not able to find a way to catch the error of a dynamic import and show the complete SyntaxError. Interestingly node --unhandled-rejections=strict -e "import('./syntax-error.mjs')" or running await import('./syntax-error.mjs') from node --experimental-repl-await both display the location of the SyntaxError.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il caso di dynamic import con i comandi e l’esempio syntax-error.mjs. Inizia tracciando i percorsi mostrati in internal/modules/esm/translators.js e internal/modules/esm/module_job.js, confrontando dynamic import con static import e strict unhandled rejections. Il lavoro è completato quando un SyntaxError di dynamic-import intercettato include la posizione nel sorgente e il contesto del codice che causa l’errore.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, nodejs
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100