Skip to content

JSRuntimeContext.Import method ​

Imports a module or module property from JavaScript.

C#
public JSValue Import(string? module, string? property = null, bool esModule = false)
parameterdescription
moduleName of the module being imported, or null to import a global property. This is equivalent to the value provided to import or require() in JavaScript. Required if property is null.
propertyName of a property on the module (or global), or null to import the module object. Required if module is null.
esModuleTrue to use dynamic import(); false (default) to use require(), only when module names a module. When it is null or global, this parameter has no effect; the global value is returned directly. In Node.js 22.12 and later (including LibNode 26), require() also loads ES modules unless their module graph uses top-level await (ERR_REQUIRE_ASYNC_MODULE).

Return Value ​

The imported value. When dynamically importing a module, this is a JS promise that resolves to the module namespace or requested property.

Exceptions ​

exceptioncondition
ArgumentNullExceptionBoth module and property are null.
InvalidOperationExceptionThe RequireFunction or ImportFunction property was not initialized.

See Also ​

Released under the MIT license