javascript - URLPattern class in Node v23.10 returns Uncaught ReferenceError: URLPattern is not defined - Stack Overflow

I'm trying out the URLPattern class in Node v23.10, installed with nvmWhen I ran the following in

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
  • Have you checked node --help and see if there's a relevant flag? – Evert Commented Mar 14 at 17:17
  • I've never done that. Thanks for the tip, @Evert – ፍፁም Commented Mar 14 at 17:28
Add a comment  | 

1 Answer 1

Reset to default 2

Node.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 the node: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'});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744640305a4585398.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信