Plugin System Basics: From Debugging Editor Errors to Runtime Module Resolution

    This article builds a practical mental model for plugin development, breaking the toolchain into five stages: dependency foundation, source and type checking, build and bundling, publishing and distribution, and runtime resolution. It explains the four common causes of editor red squiggles, clarifies three frequently confused configuration fields, and shows why a build can pass while runtime module lookup still fails. Developers will learn a stage-by-stage debugging approach that turns vague errors into locatable engineering problems.

    1. Why You Need a Mental Model Before Writing Plugins

    Many developers treat their first plugin as a lightweight task: write a function and hook it up. They get blocked almost immediately by red squiggles in the editor, then hit module resolution failures at runtime. The root cause is rarely coding ability. It is the lack of a whole-chain understanding: how source code is statically checked, how it is compiled into artifacts, what structure those artifacts are published in, and what rules the runtime uses to locate them.

    A practical mental model splits the chain into five stages: dependency foundation → source and type checking → build and bundling → publishing and distribution → runtime resolution. If the conventions of any stage are misaligned, the failure surfaces as either “red squiggles” or “module not found.” So when troubleshooting, locate which stage broke first instead of immediately suspecting your business code.

    This article stays in a general technical context and is not tied to any specific tool. Everything covered here is a common engineering convention in plugin-based systems.

    2. The Foundation: A Dependency Injection Container and Its Vendoring Strategy

    Mature extensible systems usually do not let plugins reference each other directly. Instead, they introduce a lightweight dependency injection (DI) container as the foundation. A plugin declares to the container “what services I need,” and the container hands over instances at the appropriate time. This yields three direct benefits:

    • Decoupling: plugins depend on service identifiers and interfaces, not concrete implementations;
    • Controlled lifecycle: creation, reuse, and disposal of services are managed centrally by the container;
    • Testability: in tests, you swap in stub implementations for real services.

    One detail worth noting: some systems vendor the core container into the repository as source code rather than pulling it in as a regular dependency. This has an easily overlooked consequence. Type definitions come from that in-repo source, while the same-named type package you install in an external project is, in the type system, a different declaration. The two are structurally similar but have different identities, so assignment triggers a type incompatibility error. Recognizing this can save hours.

    An illustrative plugin declaration:

    1. // Declare required services via dependency injection instead of importing concrete implementations
    2. export const inject = ['logger', 'config'];
    3. export function apply(ctx: Context) {
    4. ctx.logger.info('plugin loaded');
    5. ctx.on('event:name', (payload) => {
    6. // handling logic
    7. });
    8. }

    3. Your First Plugin: Four Causes of Editor Red Squiggles

    Editor red squiggles are feedback from the static checking stage. The common causes fall into four categories, ordered from highest to lowest troubleshooting value:

    1. The module is not installed or not declared in the dependency manifest. The editor cannot resolve the module’s declaration file and reports “cannot find module or its type declarations.”
    2. The module resolution mode does not match the module system. A poor combination of the module system and resolution strategy declared in the compiler configuration causes relative imports with extensions to be treated as invalid.
    3. Duplicate type sources or inconsistent identities. This is the inlined source versus external type package situation described above, producing a structural conflict where things “look the same but are incompatible.”
    4. Insufficient configuration coverage. The source directory is not included in the configuration’s scope, or declaration files are not included, causing global type augmentation to fail.

    Recommended order: first confirm the dependency actually exists in the dependency tree, then check the module-related fields in the compiler configuration, then isolate type conflicts with a minimal reproduction project, and finally check the file coverage of your configuration. Pinning down variables one at a time converges faster than changing five things at once.

    4. Configuration Clarification: Three Fields That Are Most Often Confused

    • target: determines the syntax level of the compiled output, affecting whether newer syntax is preserved or needs to be downleveled.
    • module: determines how the output is organized as modules, directly affecting how it is loaded at runtime.
    • moduleResolution: determines “how the compiler finds files,” for example whether explicit extensions are required and whether export map fields are read.

    The three must be consistent with each other. A common mistake is setting the “resolution strategy” as if it were the “output format,” which results in a successful compile but a runtime failure. Another mistake is hand-writing path mappings to mask the problem; the mapping table grows longer and longer until nobody dares to touch it. A safer approach is to keep the project structure aligned with the module resolution convention, treating mappings as a temporary measure rather than a long-term solution.

    5. Build and Artifacts: Turning “It Runs” into “It Ships”

    The goal of the build stage is not shrinking bundle size but producing artifacts with a deterministic structure that can be reliably located. Three things should be made explicit: the entry file path, the artifact directory structure, and whether runtime dependencies need to be inlined. If the artifacts depend on many external packages, distribution requires either declaring a complete dependency manifest or choosing to inline for self-containment. Pick one; do not leave it ambiguous.

    Also ensure type declarations are generated in sync with the artifacts, so consumers get type hints along with the implementation.

    6. Runtime Resolution: Why “Module Not Found” Happens Even After a Successful Compile

    Runtime lookup rules are not equivalent to compile-time rules. Compile time only cares about “whether the types match.” Runtime cares about “whether the file is really in that location and whether the export map permits that kind of access.” Three high-frequency causes:

    • The export map does not expose subpaths, so deep path access is rejected;
    • The artifact directory hierarchy does not match the entry declaration;
    • Missing case, extension, or index file, exposed on case-sensitive file systems.

    The diagnosis is straightforward: print the path actually resolved at runtime and compare it segment by segment with the expected path; then confirm whether the package’s export field allows that subpath.

    7. Publishing and Versioning: Keeping Upgrades from Becoming Incidents

    Before publishing, lock down a versioning strategy and a changelog, and make clear which changes break compatibility. Plugins collaborate through service identifiers, so interface changes must be treated as breaking changes. If you use a private artifact repository, ensure versions are immutable and traceable, and pair that with logging services and monitoring alerts so you can roll back quickly when something goes wrong.

    8. Cloud and Engineering Recommendations

    Once a plugin system enters team collaboration, general cloud capabilities can fill engineering gaps: use object storage to host build artifacts, use a container platform to run stateless build jobs, use a message queue to decouple build triggering from artifact archiving, and use logging and monitoring to track load failure rates. If you use the relevant general capabilities from Baidu AI Cloud, the same three principles apply: addressable artifacts, observable processes, and rollback-able versions.

    9. Conclusion

    The hard part of plugin development has never been syntax; it is chain consistency. Verify the five stages separately—dependency foundation, static checking, build artifacts, publishing and distribution, and runtime resolution—and both red squiggles and module-not-found problems turn from “black magic” into locatable engineering problems.