Dynamic import does not show location of SyntaxError
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.3k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 283
Beschreibung
// 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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere den Fall mit dynamischem Import anhand der Befehle und des Beispiels syntax-error.mjs. Beginne damit, die in internal/modules/esm/translators.js und internal/modules/esm/module_job.js gezeigten Pfade nachzuverfolgen und dynamic import mit static import und strict unhandled rejections zu vergleichen. Erledigt ist die Aufgabe, wenn ein abgefangener dynamic-import SyntaxError die Quellposition und den Kontext des fehlerhaften Codes enthält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, nodejs
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100