I'm trying out the URLPattern
class in Node v23.10, installed with nvm
When I ran the following in the cli or as an executable
const p = new URLPattern({pathname: 'annotations/:id'})
I got this
Uncaught ReferenceError: URLPattern is not defined
I understand this is an experimental feature, but there's no guidance in the docs and examples I've read as to what flag(s) to run this script with.
I'm trying out the URLPattern
class in Node v23.10, installed with nvm
When I ran the following in the cli or as an executable
const p = new URLPattern({pathname: 'annotations/:id'})
I got this
Uncaught ReferenceError: URLPattern is not defined
I understand this is an experimental feature, but there's no guidance in the docs and examples I've read as to what flag(s) to run this script with.
Share Improve this question edited Mar 14 at 17:42 Mureinik 313k54 gold badges363 silver badges392 bronze badges asked Mar 14 at 17:08 ፍፁምፍፁም 5711 bronze badges 2 |1 Answer
Reset to default 2Node.js' API documentation really doesn't seem to explain this, but the release notes for Node.js 23.8.0, where it was introduced, do:
The
URLPattern
constructor is exported from thenode:url
module and will be available as a global in Node.js 24.
I.e., in Node.js 23.8.0 and above, you can access it by requiring the node:url
module:
const URLPattern = require('node:url').URLPattern;
const p = new URLPattern({pathname: 'annotations/:id'});
node --help
and see if there's a relevant flag? – Evert Commented Mar 14 at 17:17