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

TypeError in version 1.2.1 #56

Closed
catriuspham opened this issue Sep 17, 2018 · 9 comments
Closed

TypeError in version 1.2.1 #56

catriuspham opened this issue Sep 17, 2018 · 9 comments
Labels

Comments

@catriuspham
Copy link

I just updated to the newest version and encountered this error:

TypeError: Object is not a constructor (evaluating 'new Hashids()')

@jd327
Copy link
Collaborator

jd327 commented Sep 17, 2018

This works for me:

const Hashids = require('hashids');
const h = new Hashids();
console.log(h.encode(1, 2, 3));

How are you using it? And what version of Node?

cc @niieani

@techwes
Copy link

techwes commented Sep 17, 2018

Running into the same problem. Using Node 8.11.3 and requiring it via:

import Hashids from 'hashids'
// ...
const generator = new Hashids('Not Real', 5, 'ABCDEFGHJKMNPQRTWXY234689')

which transpiles into:

var _hashids = require('hashids');
var _hashids2 = _interopRequireDefault(_hashids);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//...
var generator = new _hashids2.default('Not Real', 5, 'ABCDEFGHJKMNPQRTWXY234689')

via babel
So exact error is: TypeError: _hashids2.default is not a constructor

@jd327 jd327 closed this as completed in 1b566c6 Sep 17, 2018
jd327 pushed a commit that referenced this issue Sep 17, 2018
Fix importing via babel interop (fixes #56)
@jd327 jd327 reopened this Sep 17, 2018
@jd327
Copy link
Collaborator

jd327 commented Sep 17, 2018

Thanks @techwes.
Sorry, that was my bad.

@niieani pushed a fix; 1.2.2 has been published.
Can you give it a try?

@catriuspham
Copy link
Author

catriuspham commented Sep 18, 2018

@ivanakimov The issue is still there.

@niieani
Copy link
Owner

niieani commented Sep 18, 2018

@catriuspham can you make a minimal reproduction repo please? I've added 5 tests to cover various ways of importing/requiring hashids, including the one you cited: https://github.com/ivanakimov/hashids.js/blob/master/tests/requiring.js#L13

@catriuspham
Copy link
Author

catriuspham commented Sep 19, 2018

@niieani In 1.2.2, the issue can be temporarily fixed with

var Hashids = require('hashids').default;

Hope this help. I'm kinda busy now so I don't have time to reproduce the bug any further. For my own project, I just pin the version to the bug-free verrsion 1.0.2.

@jd327
Copy link
Collaborator

jd327 commented Sep 23, 2018

Closing. If still an issue, please re-open with reproducible code.

@jd327 jd327 closed this as completed Sep 23, 2018
@niieani
Copy link
Owner

niieani commented Aug 15, 2019

🎉 This issue has been resolved in version 2.0.0-prerelease.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

niieani added a commit that referenced this issue Aug 15, 2019
wrong order was causing babel interop to fail
niieani pushed a commit that referenced this issue Aug 15, 2019
Fix importing via babel interop (fixes #56)
@niieani
Copy link
Owner

niieani commented Aug 31, 2019

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

4 participants