-
Notifications
You must be signed in to change notification settings - Fork 378
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
Fix incompatibility with perf_hooks accross nodejs versions #515
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks 👍
We could also just make a major release dropping node 10, 12 and 17 |
Is there any update on this PR? We are facing the same issue and would be awesome to have it ready. @SimenB Thanks! |
I agree that it's reasonable to just drop 10, 12 and 17. v12 went EOL in April. @mireiaangles1109 can you use a current version of Node.js, or are you still running into issues with v14+? |
Thanks for your reply @zbjornson In our project we are using Node 16, so my guess is that the issues are coming with the rollup3 upgrade Thanks! |
hey @zbjornson , the actual issue is that rollup DOES NOT handle require in try {} catch {}, this causes perf_hooks to be undefined in the code, hence this modification is REQUIRED for it to work properly (By this I mean correctly fail due to missing perf_hooks but not break the whole code) in the current code. The solution is either to get rid of the try {} catch {} arround the importation of perf_hooks, or to merge the changes I've got in this PR. As of now your code is not compatible with building with rollup (meaning vite and all the other stuff that uses rollup as well) |
It would be awesome to get this merged, we are also facing similar issue with rollup. |
It looks like Rollup has supported optional catch bindings since 2018. Do you need to set rollup's parser to the right ES version? rollup/rollup#2455 |
We're having the same problem here using SvelteKit and Vite, it would great to merge this PR |
@gasparearmato6991 do you have Vite configured for the right ecmascript target? I have no idea if it will work to use Vite with this Node.js-only library, either. |
@zbjornson yes we're pointing the the right ES target, as mentioned before the problem here is that rollup does not handle the require in a try-catch block |
I think we can land this now and just revert when it's non-conditional in a future major version |
When using rollup to build an all-in-one esm module, rollup fails to properly handle require in try{}catch{} code.
It causes perf_hooks to not be defined ( that would happens if perf_hooks isn't implemented in current nodejs version) and breaks code accessing perf_hooks constants fields :
It'd be nice to either require it (and as such require recent nodejs version) or make sure the codebase is compatible when it is not present.
This change is for enabling perf_hooks to not exists. It would also be possible to make it a hard requirement.
Note :
perf_hooks.constants
is defined only on nodejs version starting with the following :Because of this I'm unsure the rest of the gc.js code will work correctly with nodejs >= 10 & <= 12.17
(Nodejs 10 requirement is from your package.json
engines
field)