How to Resolve 'X [ERROR] Could Not Resolve \"module name\"' Errors for External JavaScript Libraries within Action Mod Development in Spotfire

How to Resolve 'X [ERROR] Could Not Resolve \"module name\"' Errors for External JavaScript Libraries within Action Mod Development in Spotfire

book

Article ID: KB0070077

calendar_today

Updated On:

Products Versions
Spotfire Analyst 14.4 and Higher

Description

When developing an action mod that uses JavaScript libraries, you may encounter the error "X [ERROR] Could Not Resolve '<module name>'" (e.g., "X [ERROR] Could Not Resolve 'moment'") during the build process (`npm run build`), even if the library has been installed (`npm install <package name>`) and imported correctly into your script. This issue often arises because additional configurations or plugins may be required for the bundler to recognize and include external dependencies properly.

Environment

All

Resolution

To resolve this issue:

1. In `tsconfig.json, add:

"moduleResolution": "Bundler"
 

2. In `esbuild.config.js`, add:
 

mainFields: ["main"]
 

After making these changes, you can import the module as follows in your script:
 

import moment from "<ModuleName>";

For example:
import moment from "moment";
 

 

Issue/Introduction

When developing an action mod with third-party or external JavaScript libraries, you may encounter errors such as "X [ERROR] Could Not Resolve 'module name'" during the build process, even if the libraries are imported and installed correctly. This article guides resolving such errors and ensuring that external libraries are properly handled in action mod development.

Additional Information