Chapter 2 Usage of Third-Party Libraries
How to Get Usable Third-Party Libraries
The third-party libraries available through ohpm are summarized on Gitee: Summary of Third-Party Components Available on OpenHarmony. Third-party library contents are categorized by different functions. Developers can refer to them as needed.

How to Use ohpm to Introduce Third-Party Libraries
Solution
- Method One:
- Open the Terminal window and enter the entry directory with the following command.
cd entry
* Taking "dayjs" as an example, execute the following command to install it.
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 enter the entry directory with the following command.
cd entry
* Execute the command to install.
ohpm install
* Reference directly in the corresponding js file.
import dayjs from 'dayjs';