Importing individual method fails with "Class is not a constructor"
See original GitHub issueIssue Description
I’d like to import only the dereference
method (the other parts of this module should ideally be tree-shaken out), but it seems this is currently not possible because of this error:
> const {dereference} = require("json-schema-ref-parser")
> dereference({}).then(console.log)
Thrown:
TypeError: Class is not a constructor
at $RefParser.dereference (node_modules/json-schema-ref-parser/lib/index.js:227:18)
Importing the default export works as expected in comparison:
> const parser = require("json-schema-ref-parser")
> parser.dereference({}).then(console.log)
{}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Unable to import javascript class. TypeError - node.js
js) imports my socket server module and connects to the socket server. const socket = require('./socket') class Worker { constructor() ...
Read more >TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >Built-in Exceptions — Python 3.11.1 documentation
Two exception classes that are not related via subclassing are never ... while others are usually called only with a single string giving...
Read more >ES6 Class Mocks - Jest
Jest can be used to mock ES6 classes that are imported into files you want to test. ES6 classes are constructor functions with...
Read more >Classes and Modules | Advanced JavaScript
The constructor, if not necessary for a JavaScript class, but there can only be one method with the name constructor in a class....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
json-schema-ref-parser
now always fails on TypeScript 4.4 with the same error.The underlying issue is this: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#more-compliant-indirect-calls-for-imported-functions
By spec, you cannot bind an exported method, which is causing the code to error on
node_modules/@apidevtools/json-schema-ref-parser/lib/index.js:160
:For anyone struggling to get this working, here’s a hacky workaround:
Anyone able to get a pull request over to fix this? Or is it not a problem anymore?