Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Cloudflare Docs
Log in

When you write a Worker, you may need to import packages fromnpm. Many npm packages rely on APIs from theNode.js runtime, and will not work unless these Node.js APIs are available.

Cloudflare Workers provides a subset of Node.js APIs in two forms:

  1. As built-in APIs provided by the Workers Runtime. Most of these APIs arefull implementations of the corresponding Node.js APIs, while a few arepartially supported or non-functional stubs intended for the APIs to beavailable for import only but not for actual use.
  2. As polyfill shim implementations thatWrangler adds to your Worker's code, allowing it to import the module, but calling API methods will throw errors.

Get Started

To enable built-in Node.js APIs and add polyfills, add thenodejs_compat compatibility flag to yourwrangler configuration file, and ensure that your Worker'scompatibility date is 2024-09-23 or later.Learn more about the Node.js compatibility flag and v2.

{
"$schema":"./node_modules/wrangler/config-schema.json",
"compatibility_flags":[
"nodejs_compat"
],
"compatibility_date":"2024-09-23"
}

Supported Node.js APIs

The runtime APIs from Node.js listed below as "🟢 supported" are currently natively supported in the Workers Runtime. Item listed as "🟡 partially supported" are either only partially implemented or are implemented as non-functional stubs.

Deprecated or experimental APIs from Node.js, and APIs that do not fit in a serverless context, are not included as part of the list below:

API NameNatively supported by the Workers Runtime
Assertion testing🟢 supported
Asynchronous context tracking🟢 supported
Async hooks🟡 partially supported (non-functional)
Buffer🟢 supported
Child processes🟡 partially supported (non-functional)
Cluster🟡 partially supported (non-functional)
Console🟡 partially supported
Crypto🟢 supported
Debugger🟢 supported viaChrome Dev Tools integration
Diagnostics Channel🟢 supported
DNS🟢 supported
Errors🟢 supported
Events🟢 supported
File system🟢 supported
Globals🟢 supported
HTTP🟢 supported
HTTP/2🟡 partially supported (non-functional)
HTTPS🟢 supported
Inspector🟡 partially supported viaChrome Dev Tools integration
Module🟡 partially supported
Net🟢 supported
OS🟡 partially supported
Path🟢 supported
Performance hooks🟡 partially supported
Process🟢 supported
Punycode (deprecated)🟢 supported
Readline🟡 partially supported (non-functional)
REPL🟡 partially supported (non-functional)
Query strings🟢 supported
SQLite⚪ not yet supported
Stream🟢 supported
String decoder🟢 supported
Test runner⚪ not supported
Timers🟢 supported
TLS/SSL🟡 partially supported
UDP/datagram🟡 partially supported (non-functional)
URL🟢 supported
Utilities🟢 supported
V8🟡 partially supported (non-functional)
VM🟡 partially supported (non-functional)
Web Crypto API🟢 supported
Web Streams API🟢 supported
Zlib🟢 supported

Unless otherwise specified, native implementations of Node.js APIs in Workers are intended to match the implementation in theCurrent release of Node.js.

If an API you wish to use is missing and you want to suggest that Workers support it, please add a post or comment in theNode.js APIs discussions category on GitHub.

Node.js API Polyfills

Node.js APIs that are not yet supported in the Workers runtime are polyfilled viaWrangler, which usesunenv. If thenodejs_compatcompatibility flag is enabled, and your Worker'scompatibility date is 2024-09-23 or later, Wrangler will automatically inject polyfills into your Worker's code.

Adding polyfills maximizes compatibility with existing npm packages by providing modules with mocked methods. Calling these mocked methods will either noop or will throw an error with a message like:

[unenv] <method name> is not implemented yet!

This allows you to import packages that use these Node.js modules, even if certain methods are not supported.

Enable only AsyncLocalStorage

If you need to enable only the Node.jsAsyncLocalStorage API, you can enable thenodejs_als compatibility flag:

{
"$schema":"./node_modules/wrangler/config-schema.json",
"compatibility_flags":[
"nodejs_als"
]
}

[8]ページ先頭

©2009-2025 Movatter.jp