Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.0 - incorrect TypeScript exports resulting in TypeError #75

Closed
jan-molak opened this issue Jun 5, 2022 · 6 comments
Closed

2.1.0 - incorrect TypeScript exports resulting in TypeError #75

jan-molak opened this issue Jun 5, 2022 · 6 comments
Assignees
Labels

Comments

@jan-molak
Copy link

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:

Screenshot 2022-06-06 at 00 06 20

Type definitions changed in v2.1.0 suggest one should import ErrorStackParser using the default export as follows:

import ErrorStackParser from 'error-stack-parser';

ErrorStackParser.parse(...) // TypeError in 2.1.0

which is different from v2.0.7, where we'd import the module like this:

import * as ErrorStackParser from 'error-stack-parser';

ErrorStackParser.parse(...)

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 a TypeError:

TypeError: Cannot read properties of undefined (reading 'parse')

Your Environment

  • Package version: 2.1.0
  • Browser name and version: Node 16.13.1
  • OS version (desktop or mobile): macOS 12.4
  • Link to your project:

Possible Workaround

Ignore the type definitions and use a var require instead:

const ErrorStackParser = require('error-stack-parser');

Possible Solution

If possible, I'd suggest reverting the change to error-stack-parser.d.ts:

- export default ErrorStackParser;
+ export = ErrorStackParser;

Or, if you prefer to use default exports, the associated JavaScript code would need to change to use

+ module.exports.default = ErrorStackParser
- module.exports = ErrorStackParser

If using the default export, I'd also suggest bumping the major version number, since this change is not backwards compatible.

@jan-molak jan-molak added the a:bug label Jun 5, 2022
@eriwen
Copy link
Member

eriwen commented Jun 5, 2022

Hi @jan-molak. Thanks for the report.

What I'm going to do here is revert the change (done in afc0a4c) 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 #45 — I'd prefer to support a single way to invoke ErrorStackParser.parse() for maximum compatibility.

Does this work for you?

@eriwen eriwen self-assigned this Jun 6, 2022
@jan-molak
Copy link
Author

Sure, sounds great! Thanks for getting back to me so quickly 👍🏻

@AnyGong
Copy link

AnyGong commented Jun 6, 2022

@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?

jan-molak added a commit to serenity-js/serenity-js that referenced this issue Jun 6, 2022
Pinned versions of error-stack-parser and stackframe as per stacktracejs/error-stack-parser#75
@jan-molak
Copy link
Author

jan-molak commented Jun 6, 2022

@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");

@eriwen
Copy link
Member

eriwen commented Jun 6, 2022

Ah, sorry about that @jan-molak. error-stack-parser v2.1.3 fixes both of these issues.

@eriwen eriwen closed this as completed Jun 6, 2022
@jan-molak
Copy link
Author

jan-molak commented Jun 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants