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

formatNumber method from Currency Module is throwing error while running in a non-browser environment (e.g., Node.js) #36

Closed
sakigo9 opened this issue Dec 9, 2023 · 3 comments · Fixed by #44

Comments

@sakigo9
Copy link
Contributor

sakigo9 commented Dec 9, 2023

Steps to reproduce the issue

  1. Firstly I installed the @razorpay/i18nify package inside my Node app using npm i @razorpay/i18nify.
  2. Using the latest version of the app i.e. "@razorpay/i18nify": "^1.2.1".
"dependencies": {
    "@razorpay/i18nify": "^1.2.1",
    "nodemon": "^3.0.2"
}
  1. Then, I tried using the method called formatNumber from the Currency Module. Refer to the below code to replicate the issue
const { formatNumber } = require("@razorpay/i18nify");
console.log(formatNumber("1000.5", { currency: "USD" }));
  1. Received following error
Screenshot 2023-12-09 at 11 00 45 PM

 

Expected vs. Actual behavior

  1. To verify this method I used the same method in the browser environment and it worked well.
  2. Refer to the following image which verified that this method worked well with a browser-based environment (used React.js)
Screenshot 2023-12-09 at 11 04 34 PM

 

Root Cause(Based on my observation)

The window.navigator object is specific to web browsers and is not available in Node.js. However, if we navigate here then we can observe that we are trying to use navigator which will work well for a browser environment. But Node.js is not running in a browser context, so you won't have access to browser-specific APIs like window.navigator.

 
I've reproduced the issue locally. I have a fix for this solution, once this issue is verified, please allow me to fix this issue through a PR.

Please let me know if any additional information is required.

@sakigo9
Copy link
Contributor Author

sakigo9 commented Dec 10, 2023

Just a quick question. If someone raises an issue then can't they fix that issue as well?
For this issue, I raised an issue and asked if I could fix it or not. But didn't get the opportunity to contribute.

Did I miss something or someone outside Razorpay are not allowed to fix issues? Can someone guide me on this?

sakigo9 added a commit to sakigo9/i18nify that referenced this issue Dec 10, 2023
@RgnDunes
Copy link
Collaborator

@sakigo9 to answer your above question, if someone raises an issue then they CAN fix that issue as well. Thanks for raising the issue and a PR for it's fix. Have left some comments, please address those.

@sakigo9
Copy link
Contributor Author

sakigo9 commented Dec 11, 2023

Thanks for answering @RgnDunes.
Sure will have a look at your comment on the PR.

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

Successfully merging a pull request may close this issue.

2 participants