Skip to content

JSRuntimeContext.ImportAsync method

Imports a module or module property from JavaScript.

C#
public Task<JSValue> ImportAsync(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 import an ES module; false to import a CommonJS module (default).

Return Value

A task that results in the imported value. When importing from an ES module, the task directly results in the imported value (not a JS promise).

Exceptions

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

See Also

Released under the MIT license