Skip to content

2.1.0 - incorrect TypeScript exports resulting in TypeError #75

Closed
@jan-molak

Description

@jan-molak

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions