Streamlining ESHOPMAN Admin UI Development: Resolving TypeScript Path Alias Issues

Streamlining ESHOPMAN Admin UI Development: Resolving TypeScript Path Alias Issues

As an ESHOPMAN developer, building robust plugins with custom Admin UI extensions is a powerful way to enhance your storefront management experience within HubSpot. Leveraging Node.js and TypeScript, developers often utilize path aliases (like @/) to maintain clean, organized, and easily maintainable codebases. However, a specific challenge has been identified regarding how these aliases are handled during the ESHOPMAN Admin UI build process.

This community insight delves into a common issue where TypeScript path aliases, while perfectly functional for your ESHOPMAN plugin's backend logic, fail to resolve correctly when building your Admin UI extensions. Understanding this behavior and implementing the right solutions is crucial for a smooth development workflow.

The Challenge: Unresolved Path Aliases in ESHOPMAN Admin UI Builds

Developers configure TypeScript path aliases in their tsconfig.json files, often within the src/admin/ directory of their ESHOPMAN plugins. This setup is standard practice, allowing for cleaner imports such as:

import { useCompanies } from "@/hooks/api";
import { DataTable } from "@/components";

While the ESHOPMAN backend build process correctly interprets these aliases, the build step for Admin UI extensions (triggered by commands like ESHOPMAN plugin:build or ESHOPMAN plugin:publish) encounters resolution errors. Instead of successfully building, you might see messages indicating that the bundler failed to resolve these aliased imports.

Understanding the Root Cause

The core of this issue lies in ESHOPMAN's internal Admin UI bundler. This system, which relies on a Vite-like configuration, generates its build setup without explicitly configuring resolve.alias for TypeScript path aliases. Crucially, it also doesn't automatically integrate a plugin like vite-tsconfig-paths to handle these configurations.

During the build, the bundler's current working directory is the plugin's root, not the src/admin/ directory where your specific Admin UI tsconfig.json (containing the aliases) resides. Consequently, the bundler defaults to the root tsconfig.json, which typically lacks the Admin UI's specific path alias configurations. This leads to the aliased imports being treated as bare package specifiers, causing Rollup (part of the internal build process) to fail resolution.

Temporary Workaround

Until a permanent fix is integrated into the ESHOPMAN platform, the most straightforward workaround involves replacing all aliased imports with relative imports within your Admin UI source files. For example:

  • Before (breaks build):
    import { useCompanies } = "@/hooks/api";
    
  • After (works):
    import { useCompanies } = "../../hooks/api/index";
    

While effective, this method can be tedious and impact code readability, especially in larger projects. It's a temporary measure to ensure your Admin UI extensions can be built and deployed to your HubSpot CMS storefront.

Suggested Fix for ESHOPMAN Developers and Platform Enhancements

The ideal solution involves an enhancement to ESHOPMAN's internal Admin UI bundler. The plugin() function within the bundler should be updated to:

  • Read the src/admin/tsconfig.json: Properly identify and parse the paths entries defined in the Admin UI's specific TypeScript configuration.
  • Apply as Vite resolve.alias: Translate these paths entries into corresponding resolve.alias configurations for the internal Vite build process.
  • Integrate vite-tsconfig-paths: Alternatively, adding a plugin like vite-tsconfig-paths, configured to point to the Admin UI's tsconfig.json, would achieve the desired resolution.

A conceptual example of integrating vite-tsconfig-paths:

import tsconfigPaths from "vite-tsconfig-paths";

const pluginC
  plugins: [
    // ... other plugins
    tsconfigPaths({ projects: [path.resolve(options.root, "src/admin/tsconfig.json")] }),
    // ... ESHOPMAN specific plugins
  ],
  // ...
};

By addressing this, ESHOPMAN developers can continue to leverage the benefits of TypeScript path aliases for cleaner, more modular Admin UI extension development, ensuring a seamless experience when managing storefronts via HubSpot.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools