Chapter 2 Referencing and Using Third-Party Libraries
How to obtain and integrate available third-party libraries
The OpenHarmony Package Manager (ohpm) provides access to a curated collection of third-party libraries available on Gitee: OpenHarmony Third-Party Component Repository ,This repository categorizes third-party components by functionality (e.g., networking, UI, multimedia) to help developers quickly locate and integrate required libraries into their projects.

How to use ohpm to import third-party libraries
Resolution Steps
Method 1:
- Open the Terminal window and use the following command to navigate to the entry directory:
cd entry
* For example, to install the 'dayjs' library, execute the following command:
ohpm install dayjs
* Import the library directly into the corresponding JavaScript file.
import dayjs from 'dayjs';
Method 2:
Navigate to the 'entry' directory within the project folder and locate the 'oh-package.json5' configuration file in that directory.
Add the desired third-party library dependencies to the oh-package.json5 configuration file. Using 'dayjs' as an example, the configuration syntax would appear as follows:
{
"dependencies": {
"dayjs": "^1.10.4",
}
}
* Open the Terminal window and use the following command to navigate to the entry directory:
cd entry
* Run the installation command to complete the dependency setup.
ohpm install
* Import the library directly into the corresponding JavaScript file.
import dayjs from 'dayjs';