Chapter 2 Third-Party Library Usage
How to Get Available Third-Party Libraries
Third-party and fourth-party libraries available through ohpm are summarized on Gitee: Summary of Third-Party Components Directly Usable on OpenHarmony. The content is categorized by different functions, and developers can refer to it based on their needs.

How to Use ohpm to Import Third-Party Libraries
Solution
Method One:
- Open the Terminal window and use the following command to enter the entry directory.
cd entry
* Taking "dayjs" as an example, execute the following command to install.
ohpm install dayjs
* Reference directly in the corresponding js file.
import dayjs from 'dayjs';Method Two:
- Open the entry directory under the project directory and find the oh-package.json5 file in that directory.
- Write the third-party library you want to install in the oh-package.json5 file. Taking "dayjs" as an example, the example is as follows:
{
"dependencies": {
"dayjs": "^1.10.4",
}
}
* Open the Terminal window and use the following command to enter the entry directory.
cd entry
* Execute the command to install.
ohpm install
* Reference directly in the corresponding js file.
import dayjs from 'dayjs';