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

Cannot read properties of undefined (reading 'env') #10329

Closed
3 tasks done
NathanWalker opened this issue Jun 24, 2023 · 6 comments
Closed
3 tasks done

Cannot read properties of undefined (reading 'env') #10329

NathanWalker opened this issue Jun 24, 2023 · 6 comments

Comments

@NathanWalker
Copy link
Contributor

Issue Description

While running a project you may run into this error:

Cannot read properties of undefined (reading 'env')

Reproduction

No response

Relevant log output (if applicable)

No response

Environment

No response

Please accept these terms

@NathanWalker
Copy link
Contributor Author

This appears related to a recent transient npm dependency that some plugins may rely on. To resolve, add this dependency to your package.json, then ns clean:

"qs": "npm:querystring@^0.2.1"

@NathanWalker NathanWalker pinned this issue Jun 24, 2023
@Adelrisk
Copy link

Adelrisk commented Jul 7, 2023

Thanks for this problem description and solution. Unfortunately, I don't understand the solution. It seems very unconventional.

It appears that the package qs should be resolved with the npm package querystring in the (semantically equivalent) version ^0.2.1. However, I can't find a package with that name. What may I have misunderstood?

@rigor789
Copy link
Member

rigor789 commented Jul 7, 2023

@Adelrisk

"qs": "npm:querystring@^0.2.1"

will install the querystring@^0.2.1 package but alias/name it as qs (so it will be in node_modules/qs/). It's definitely a workaround until a cleaner/better solution is found (we're still thinking about it, as we want something that will work long-term).

@Adelrisk
Copy link

Adelrisk commented Jul 7, 2023

The real confusion arose because the npm API (both web and cli) hides the package from all searches (https://www.npmjs.com/search?q=querystring and npm search "querystring" respectively), probably because it has been deprecated. (I try to audit and/or review the changes to my projects.)

Thanks for the confirmation.

@rigor789
Copy link
Member

rigor789 commented Jul 7, 2023

It's here, but yes it is deprecated: https://www.npmjs.com/package/querystring

@NathanWalker
Copy link
Contributor Author

NathanWalker commented Nov 5, 2023

@Adelrisk I revisited this in a project and there's another way to resolve too I wanted to mention here in case helps others.
The primary issue comes from the util package inserting some debug check outside of exported functions. This causes the webpack build to encounter process before it's defined in a bundle. You can also just apply this patch using patch-package which also resolved this issue without having to change anything in your package dependencies - see attached file and a look at the patch here:

diff --git a/node_modules/util/util.js b/node_modules/util/util.js
index 6db393e..6fecf25 100644
--- a/node_modules/util/util.js
+++ b/node_modules/util/util.js
@@ -106,14 +106,6 @@ exports.deprecate = function(fn, msg) {
 var debugs = {};
 var debugEnvRegex = /^$/;
 
-if (process.env.NODE_DEBUG) {
-  var debugEnv = process.env.NODE_DEBUG;
-  debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&')
-    .replace(/\*/g, '.*')
-    .replace(/,/g, '$|^')
-    .toUpperCase();
-  debugEnvRegex = new RegExp('^' + debugEnv + '$', 'i');
-}
 exports.debuglog = function(set) {
   set = set.toUpperCase();
   if (!debugs[set]) {

util+0.12.5.patch

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

No branches or pull requests

3 participants