Closed HariniReddyP closed 2 years ago
If you get that error, then one of window
, global
, or self
is null
in your environment.
Can you provide more details? Where and how are you using url-parse
? How can we reproduce the issue?
We are trying to test the "parse" function using chai node module, where we are just executing function using a hardcoded value 'http://localhost:1234/' which is expecting a value , but it throws the below error TypeError: Cannot read properties of null (reading 'location'). You have to use chai node module expect function to reproduce the issue.
@lpinca Even if the globalVar is an empty JSON({}), it is trying to read location which will error out for sure. That is the issue i am facing currently.
The error is thrown only if one of window
, global
, or self
is null
which is weird.
@lpinca Can we add a condition check for null as well in that scenario?
Yes, but why is it required? Those should not be null
. That is why I asked if you used the library in a special environment.
@lpinca I have global object available but the window object is null as i am testing the code using chai node module
It is not chai
. The following example does not throw any error
$ cat index.js
const parse = require('url-parse');
const { assert } = require('chai');
assert.deepEqual(
{ ...parse('http://localhost:1234/') },
{
auth: '',
hash: '',
host: 'localhost:1234',
hostname: 'localhost',
href: 'http://localhost:1234/',
origin: 'http://localhost:1234',
password: '',
pathname: '/',
port: '1234',
protocol: 'http:',
query: '',
slashes: true,
username: ''
}
);
$ node index.js
@lpinca let me check in the code where window object is made to null. Thanks for the help.
@lpinca Please go ahead and close the issue.
TypeError: Cannot read properties of null (reading 'location') at lolcation (/url-parse/index.js:76:28) at new Url (/url-parse/index.js:267:14) at Url (/url-parse/index.js:240:12)
when globalVar is {}