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

TypeError: inspect is not a function at URL.tracked.<computed> #8173

Closed
LiamWiddop opened this issue Dec 15, 2022 · 2 comments · Fixed by #8174
Closed

TypeError: inspect is not a function at URL.tracked.<computed> #8173

LiamWiddop opened this issue Dec 15, 2022 · 2 comments · Fixed by #8174

Comments

@LiamWiddop
Copy link

Describe the bug

Not sure if this is a fair point, but when creating a +page.server.ts/js file, I noticed that I was getting the following error, thereby preventing a page load:

TypeError: inspect is not a function at URL.tracked.<computed> (file:///C:/Users/.../node_modules/@sveltejs/kit/src/utils/url.js:109:11) at formatValue (node:internal/util/inspect:763:19) at formatProperty (node:internal/util/inspect:1681:11) at formatRaw (node:internal/util/inspect:1006:9) at formatValue (node:internal/util/inspect:793:10) at inspect (node:internal/util/inspect:340:10) at formatWithOptionsInternal (node:internal/util/inspect:2006:40) at formatWithOptions (node:internal/util/inspect:1888:10) at console.value (node:internal/console/constructor:323:14) at console.log (node:internal/console/constructor:359:61) This is caused by either a bug in Node.js or incorrect usage of Node.js internals. Please open an issue with this stack trace at https://github.com/nodejs/node/issues

I went into utils/url.js (line 109) and noticed that the inspect function was reliant on it being passed to tracked[Symbol.for('nodejs.util.inspect.custom')] = (depth, opts, inspect) => {...}. I assume in my case, this was not happening. To get around this, I just added this to the top of url.js import util from 'util' and changed the constant's function to this:

if (!BROWSER) {
	// @ts-ignore
	tracked[Symbol.for('nodejs.util.inspect.custom')] = (depth, opts, inspect) => {
		if(inspect) return inspect(url, opts);
		else return util.inspect.custom(url,opts);
	};
}

This fixed my issue and (after some brief testing) without detriment to the underlying functionality of Sveltekit.
Please let me know if this will have long-term consequences to my code.

Thanks in advance.

Reproduction

This bug report is just an explanation of a bug in my particular instance.

Logs

TypeError: inspect is not a function
    at URL.tracked.<computed> (file:///C:/Users/.../node_modules/@sveltejs/kit/src/utils/url.js:109:11)
    at formatValue (node:internal/util/inspect:763:19)
    at formatProperty (node:internal/util/inspect:1681:11)
    at formatRaw (node:internal/util/inspect:1006:9)
    at formatValue (node:internal/util/inspect:793:10)
    at inspect (node:internal/util/inspect:340:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2006:40)
    at formatWithOptions (node:internal/util/inspect:1888:10)
    at console.value (node:internal/console/constructor:323:14)
    at console.log (node:internal/console/constructor:359:61)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 3.74 GB / 15.90 GB
  Binaries:
    Node: 17.0.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (108.0.1462.46)
    Internet Explorer: 11.0.22000.120

Severity

annoyance

Additional Information

No response

@Conduitry
Copy link
Member

Conduitry commented Dec 15, 2022

Putting import 'util' at the top of the file is probably a bad idea because this file is also run on the browser.

The Node docs for util.inspect.custom annoyingly do not say in what version the third argument was added, but it should be there in all of the versions of Node that SvelteKit supports. We should update the pkg.engines.node field to explicitly exclude Node 17, which is not one of the LTS versions of Node. Apart from this, you really should upgrade anyway, because it has been end-of-life since June.

@LiamWiddop
Copy link
Author

No worries, thanks!

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