swc-project/swc · error

Failed to create shared tokio runtime for plugin execution

Error message

Failed to create shared tokio runtime for plugin execution

What it means

In swc's plugin module, constructing the shared tokio Runtime used for plugin execution failed. This fires on first plugin invocation when the static initializer runs and tokio cannot build a runtime — typically in environments where spawning threads is restricted or resource limits prevent runtime creation. It is a one-time initialization failure affecting all subsequent plugin executions.

Source

Thrown at crates/swc/src/plugin.rs:35

use swc_common::errors::{DiagnosticId, HANDLER};
use swc_ecma_ast::Pass;
#[cfg(feature = "plugin")]
use swc_ecma_ast::*;
use swc_ecma_loader::{
    resolve::Resolve,
    resolvers::{lru::CachingResolver, node::NodeModulesResolver},
};
use swc_ecma_visit::{fold_pass, noop_fold_type, Fold};
#[cfg(feature = "plugin")]
use swc_plugin_runner::runtime::Runtime as PluginRuntime;

/// Shared tokio runtime for plugin execution.
/// This avoids the expensive overhead of creating a new runtime for each plugin
/// call.
#[cfg(all(feature = "plugin", not(feature = "manual-tokio-runtime")))]
static SHARED_RUNTIME: Lazy<tokio::runtime::Runtime> = Lazy::new(|| {
    tokio::runtime::Runtime::new()
        .expect("Failed to create shared tokio runtime for plugin execution")
});

/// A tuple represents a plugin.
///
/// First element is a resolvable name to the plugin, second is a JSON object
/// that represents configuration option for those plugin.
/// Type of plugin's configuration is up to each plugin - swc/core does not have
/// strong type and it'll be serialized into plain string when it's passed to
/// plugin's entrypoint function.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct PluginConfig(pub String, pub serde_json::Value);

#[cfg(feature = "plugin")]
pub(crate) fn plugins(
    configured_plugins: Option<Vec<PluginConfig>>,
    plugin_env_vars: Option<Vec<Atom>>,
    metadata_context: std::sync::Arc<swc_common::plugin::metadata::TransformPluginMetadataContext>,

View on GitHub (pinned to 5176682b65)

Solutions

  1. Enable the manual-tokio-runtime feature and provide an externally created runtime
  2. Ensure the host environment allows thread spawning (required by tokio multi-thread runtime)
  3. Check that no conflicting tokio runtime is already entered on the current thread
  4. If plugins are not needed, disable the plugin feature
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/swc/src/plugin.rs:35 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/0352aea55433f4c0. Report an issue: GitHub.