1# Importing a Native Module
2
3In ECMAScript 6.0 (ES6) module design, the community uses the **import** syntax to load the content exported from other files (the ECMA specification defines the syntax specifications).
4To help you easily use this feature to import the content exported from the native module (.so), ArkTS performs adaptation and provides several import methods.
5
6## Direct Import
7Export the content from the **index.d.ts** file of a native module, and then import the content to the file.
8
9### Named Import
10```ts
11// index.d.ts corresponding to libentry.so
12export const add: (a: number, b: number) => number;
13```
14```ts
15// test.ets
16import { add } from 'libentry.so'
17add(2, 3);
18```
19
20### Default Import
21```ts
22// index.d.ts corresponding to libentry.so
23export const add: (a: number, b: number) => number;
24```
25```ts
26// test.ets
27import add from 'libentry.so'
28add.add(2, 3);
29```
30
31### Namespace Import
32```ts
33// index.d.ts corresponding to libentry.so
34export const add: (a: number, b: number) => number;
35```
36```ts
37// test.ets
38import * as add from 'libentry.so'
39add.add(2, 3);
40```
41
42## Indirect Import
43
44### Converting to Named Variables Before Export and Import
45```ts
46// test1.ets
47import hilog from '@ohos.hilog'
48export { hilog }
49```
50```ts
51// test2.ets
52import { hilog } from './test1'
53hilog.info(0x000, 'testTag', '%{public}s', 'test');
54```
55
56### Converting to Namespaces Before Export and Import
57```ts
58// index.d.ts corresponding to libentry.so
59export const add: (a: number, b: number) => number;
60```
61```ts
62// test1.ets
63export * from 'libentry.so'
64```
65```ts
66// test2.ets
67import { add } from './test1'
68add(2, 3);
69```
70Note: Namespaces cannot be used simultaneously during the export and import of native modules.
71**Negative example:**
72```ts
73// test1.ets
74export * from 'libentry.so'
75```
76```ts
77// test2.ets
78import * as add from 'file1'
79// The add object cannot be obtained.
80```
81
82## Dynamic Import
83
84### Direct Import
85```ts
86// index.d.ts corresponding to libentry.so
87export const add: (a: number, b: number) => number;
88```
89```ts
90// test.ets
91import('libentry.so').then((ns:ESObject) => {
92    ns.default.add(2, 3);
93})
94```
95### Indirect Import
96```ts
97// test1.ets
98import add from 'libentry.so'
99export { add }
100
101// test2.ets
102import('./test1').then((ns:ESObject) => {
103    ns.add.add(2, 3);
104})
105```
106
107**Note**: When dynamic loading is not supported, a file must be exported using the namespace.
108**Negative example:**
109```ts
110// test1.ets
111export * from 'libentry.so'
112```
113```ts
114// test2.ets
115import('./test1').then((ns:ESObject) => {
116    // The ns object cannot be obtained.
117})
118```
119