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

Failure during initialising environment on Node21 as navigator object is populated as an empty object #180

Open
kimdanielarthur-cowlabs opened this issue Jan 18, 2024 · 3 comments

Comments

@kimdanielarthur-cowlabs

Hi! 👋

Firstly, thanks for your work on this project! 🙂

navigator object is present in Node >21 according to node docs https://nodejs.org/en/blog/announcements/v21-release-announce#navigator-object-integration

currently this is used to detect if we are running in a browser or not. A quick fix below, there may be better ways as i think navigator might have keys set in some scenarios

Here is the diff that solved my problem:

diff --git a/node_modules/emoji-js/lib/emoji.js b/node_modules/emoji-js/lib/emoji.js
index 626a0fd..f9b1405 100644
--- a/node_modules/emoji-js/lib/emoji.js
+++ b/node_modules/emoji-js/lib/emoji.js
@@ -588,7 +588,7 @@
 		self.inits.env = 1;
 		self.replace_mode = 'img';
 		var supports_css = false;
-		if (typeof(navigator) !== 'undefined') {
+		if (typeof(navigator) !== 'undefined' && Object.keys(navigator).length > 0) {
 			var ua = navigator.userAgent;
 			if (typeof window !== 'undefined' && window.getComputedStyle){
 				try {

This issue body was partially generated by patch-package.

@iamcal
Copy link
Owner

iamcal commented Jan 18, 2024

We access only a couple of keys from the navigator object, so it might be better to do something like:

if (typeof(navigator) !== 'undefined' && "userAgent" in navigator) {

And then a few lines down, wrap the navigator.product test in a specific guard:

if ("product" in navigator){
    if (/ReactNative/i.test(navigator.product)){

I'll give this a test and see if it works as expected...

@iamcal
Copy link
Owner

iamcal commented Jan 18, 2024

Does the current trunk version work for you? I'll cut a new release if it looks good

@kimdanielarthur-cowlabs
Copy link
Author

Sorry for not replying! I moved on to another project and left my wokaround as a patch so have not tested.

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

No branches or pull requests

2 participants