最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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'});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论