Closed jan-molak closed 2 years ago
Hi @jan-molak. Thanks for the report.
What I'm going to do here is revert the change (done in afc0a4c34791ce7fd535589cf796c2714cfc3462) and use export = ErrorStackParser;
for v2.1.1 and then transition to export default ...
(updating the JS too) for 3.0.0.
The motivation for this change was to fix https://github.com/stacktracejs/error-stack-parser/issues/45 — I'd prefer to support a single way to invoke ErrorStackParser.parse()
for maximum compatibility.
Does this work for you?
Sure, sounds great! Thanks for getting back to me so quickly 👍🏻
@eriwen https://www.npmjs.com/
The 2.1.2 version can be searched, but the 2.1.2 cannot be found when the nexus
is installed and synchronized. Is there a faster and better solution?
@eriwen error-stack-parser
2.1.2 and stackframe
1.3.4 use correct exports now.
However, it looks like this line in error-stack-parser.d.ts
uses a default export from stackframe
:
import StackFrame from "stackframe";
This results in the following error:
error TS1259: Module '"[redacted]/node_modules/stackframe/stackframe"' can only be default-imported using the 'esModuleInterop' flag
I'd suggest making the following change to error-stack-parser.d.ts
:
- import StackFrame from "stackframe";
+ import StackFrame = require("stackframe");
Ah, sorry about that @jan-molak. error-stack-parser
v2.1.3 fixes both of these issues.
Hey @eriwen - apologies for being a pain, but it seems like v2.1.3 has fixed the issue with the stackframe
, but re-introduced the issue with the default export.
in v2.1.3, error-stack-parser.d.ts:
import StackFrame = require("stackframe"); // this is fine now
declare namespace ErrorStackParser {
export type {StackFrame};
/**
* Given an Error object, extract the most information from it.
*
* @param {Error} error object
* @return {Array} of StackFrames
*/
export function parse(error: Error): StackFrame[];
}
- export default ErrorStackParser;
+ export = ErrorStackParser
Hi @eriwen and many thanks for your work on
error-stack-parser
!It looks like v2.1.0 has introduced a bug in TypeScript exports, preventing consumers of
error-stack-parser
from using the library in the intended way.If you have a look at line 18 in
error-stack-parser.d.ts
in this diff:Type definitions changed in v2.1.0 suggest one should import
ErrorStackParser
using the default export as follows:which is different from v2.0.7, where we'd import the module like this:
However, the change doesn't seem to have been applied to the associated JavaScript code, which still uses the more traditional
module.exports = ErrorStackParser
export.This means that importing the default export, as per the type definitions, results in
undefined
and aTypeError
:Your Environment
Possible Workaround
Ignore the type definitions and use a var require instead:
Possible Solution
If possible, I'd suggest reverting the change to
error-stack-parser.d.ts
:Or, if you prefer to use default exports, the associated JavaScript code would need to change to use
If using the default export, I'd also suggest bumping the major version number, since this change is not backwards compatible.