You can use (new Error()).stack
to get the stack trace at the current line. it would require some additional parsing to get the line number however.
eg, console.log((new Error()).stack.split(':')[1])
will get it assuming it is at the root of the file, but once you start adding it to functions you'd need something a little more sophisticated.
console.log( "❌ the error is on the line N." + new Error().stack.split(":")[3] );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.