Dynamic import does not show location of SyntaxError
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
// 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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện trường hợp dynamic import bằng các lệnh và ví dụ syntax-error.mjs. Bắt đầu bằng cách lần theo các đường dẫn được hiển thị trong internal/modules/esm/translators.js và internal/modules/esm/module_job.js, so sánh dynamic import với static import và strict unhandled rejections. Hoàn thành khi một SyntaxError của dynamic-import được bắt lại có chứa vị trí trong mã nguồn và ngữ cảnh của đoạn mã gây lỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, nodejs
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100