-
Notifications
You must be signed in to change notification settings - Fork 57
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: Harvest is not a constructor #108
Comments
Good question, I am looking into the issue presently. Initial investigation would suggest a issue relating to recent automated updates. Will rebuild, test, and let you know. |
I have entirely shifted to import in most of my uses, so looks like I didn't properly test For the immediate moment, Thank you for reporting this issue. |
I figured it would have something to do with imports, but in the meantime, Thanks for the quick response. |
Sure thing, I realized in my foolishness that when I updated the module to support the v2 API, I had bundled it for the es6 Would you be willing to verify it once I do? |
Yes, of course. Just hit me up when you publish and I'll gladly do the test. |
The initial conversion of the module to typescript was bundling a module that supported the ES6 import, but not the commonjs require. Added an index.js to the root and modified the package json. re #108
Version 2.1.1 should have what you need. Would have been patch version less, but in my thickness I pushed up the fix without including the new file in the publish. Let me know if there is anything else. |
It works now without having to use Thank you for the quick fix. |
This is still broken when using TypeScript. The typings for
This then transpiles to:
However To fix this, the |
A workaround for now is to do the following:
Downsides of this:
I have raised a fix in #112 |
Fix #108: Export default class correctly
🎉 This issue has been resolved in version 2.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I get the same error with version 2.2.3. Maybe a regression? |
I suspect as much. Will have to get some better testing in place and ensure proper support of both commonjs and ES6 imports. |
I will investigate this shortly @simplyspoke |
I'm not able to reproduce this @robinparisi. Here is my setup: import Harvest from "harvest";
const api = new Harvest({
subdomain: 'mysubdomain',
userAgent: 'myuseragent',
concurrency: 1,
auth: { accessToken, accountId }
});
api.projectAssignments.me({})
.then(assignments => console.log(assignments)); I get some assignments printed in the console. Would you mind sharing your setup? |
I believe those experiancing the issue are trying to us the module via commonjs, so it would be using require('harvest'); |
@robinparisi A workaround for now is this:
I think some further investigation is needed to see how we can have an export which can be:
There is a related issue on the TypeScript repo: microsoft/TypeScript#2719 Anders Hejlsberg's response is a wontfix - either ES6 exports or CommonJS, but not both |
@Jameskmonger as @simplyspoke said, I'm using commonjs. No problem with the |
I am looking at a solution that will support both, my tests suggest the following: Adjusted package.json:
The contents of index.cjs.js being: Was also considering a move away from webpack. Doesn't feel like the right tool for the job in this case. |
@simplyspoke I don't think there's a need for webpack (or any bundler) at all. Just compile the typescript into the Does your solution still work nicely with TypeScript imports? |
I agree @Jameskmonger... This is a rather lightweight and simple module, so throwing a bundler in front of the packaging process doesn't feel like it gets us much. As for the imports, I tested both a ts file and js file just shifting the module loader and it looks like it should fix both needs well. Would like to get a better eye on it before pushing up the changes as I only had 15min to test my approach. Might be nice to pair with pulling out webpack. |
I do notice here that |
I like having that bit of backwards compatibility. If it reduces the chance people with have any issues, seems like a win. |
@robinparisi I believe that 2.2.4 should support require now. |
Node version: 8.9.3 / 10.7.0
Harvest version: 2.0.3
What's going on?
The text was updated successfully, but these errors were encountered: