# 支持的平台

> 英文标题：Supported platforms
> 官网原文：https://typeorm.io/docs/help/supported-platforms
> 文档版本：TypeORM v1.1
> 体例：英文原文（EN）与中文译文（ZH）逐块并列，共 30 块

---

<!-- EN -->
# Supported platforms

<!-- ZH -->
# 支持的平台

<!-- EN -->
## NodeJS

<!-- ZH -->
## NodeJS

<!-- EN -->
TypeORM is compatible with Node.js 20+ and currently each commit is tested on Node.js 20 and 24.

<!-- ZH -->
TypeORM 兼容 Node.js 20+，目前每次提交都会在 Node.js 20 和 24 上测试。

<!-- EN -->
## Browser

<!-- ZH -->
## 浏览器

<!-- EN -->
You can use [sql.js](https://sql.js.org) in the browser.

<!-- ZH -->
你可以在浏览器中使用 [sql.js](https://sql.js.org)。

<!-- EN -->
### Webpack configuration

<!-- ZH -->
### Webpack 配置

<!-- EN -->
In the `browser` folder the package also includes a version compiled as a ES2015 module. If you want to use a different loader this is the point to start. Prior to TypeORM 0.1.7, the package is setup in a way that loaders like webpack will automatically use the `browser` folder. With 0.1.7 this was dropped to support Webpack usage in Node.js projects. This means, that the `NormalModuleReplacementPlugin` has to be used to insure that the correct version is loaded for browser projects. The configuration in your webpack config file, for this plugin looks like this:

<!-- ZH -->
在 `browser` 文件夹中，该包还包含一个编译为 ES2015 模块的版本。如果你想使用不同的加载器，可以从这里入手。在 TypeORM 0.1.7 之前，该包的设置方式会让 webpack 这类加载器自动使用 `browser` 文件夹。从 0.1.7 开始，为了支持在 Node.js 项目中使用 Webpack，这一做法被取消了。这意味着必须使用 `NormalModuleReplacementPlugin` 来确保浏览器项目加载到正确的版本。在你的 webpack 配置文件中，该插件的配置如下：

<!-- EN -->
```js
plugins: [
    ..., // any existing plugins that you already have
    new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
        result.request = result.request.replace(/typeorm/, "typeorm/browser");
    }),
    new webpack.ProvidePlugin({
      'window.SQL': 'sql.js/dist/sql-wasm.js'
    })
]
```

<!-- ZH -->
```js
plugins: [
    ..., // 你已有的任何插件
    new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
        result.request = result.request.replace(/typeorm/, "typeorm/browser");
    }),
    new webpack.ProvidePlugin({
      'window.SQL': 'sql.js/dist/sql-wasm.js'
    })
]
```

<!-- EN -->
and make sure [sql-wasm.wasm file](https://github.com/sql-js/sql.js/blob/master/README.md#downloadingusing) exists in your public path.

<!-- ZH -->
并确保 [sql-wasm.wasm 文件](https://github.com/sql-js/sql.js/blob/master/README.md#downloadingusing)存在于你的公共路径中。

<!-- EN -->
### Example of configuration

<!-- ZH -->
### 配置示例

<!-- EN -->
```typescript
new DataSource({
    type: "sqljs",
    entities: [Photo],
    synchronize: true,
})
```

<!-- ZH -->
```typescript
new DataSource({
    type: "sqljs",
    entities: [Photo],
    synchronize: true,
})
```

<!-- EN -->
### Don't forget to include reflect-metadata

<!-- ZH -->
### 别忘了引入 reflect-metadata

<!-- EN -->
In your main html page, you need to include reflect-metadata:

<!-- ZH -->
在你的主 html 页面中，你需要引入 reflect-metadata：

<!-- EN -->
```html
<script src="./node_modules/reflect-metadata/Reflect.js"></script>
```

<!-- ZH -->
```html
<script src="./node_modules/reflect-metadata/Reflect.js"></script>
```

<!-- EN -->
## Capacitor

<!-- ZH -->
## Capacitor

<!-- EN -->
See [Using TypeORM with the Capacitor driver type](https://github.com/capacitor-community/sqlite/blob/master/docs/TypeORM-Usage-From-5.6.0.md) in the official Capacitor docs.

<!-- ZH -->
请参阅 Capacitor 官方文档中的[使用 TypeORM 的 Capacitor 驱动类型](https://github.com/capacitor-community/sqlite/blob/master/docs/TypeORM-Usage-From-5.6.0.md)。

<!-- EN -->
## Cordova / Ionic apps

<!-- ZH -->
## Cordova / Ionic 应用

<!-- EN -->
TypeORM is able to run on Cordova/Ionic apps using the [cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage) plugin. You have the option to choose between module loaders just like in browser package. **Important**: For use with Ionic, a custom webpack config file is needed. Note that there is currently no support for transactions when using the [cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage) plugin. See [Cordova SQLite limitations](https://github.com/storesafe/cordova-sqlite-storage#other-limitations) for more information.

<!-- ZH -->
TypeORM 能够借助 [cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage) 插件运行在 Cordova/Ionic 应用上。你可以像在浏览器包中那样在模块加载器之间做选择。**重要**：与 Ionic 一起使用时，需要一个自定义的 webpack 配置文件。注意，使用 [cordova-sqlite-storage](https://github.com/litehelpers/Cordova-sqlite-storage) 插件时目前不支持事务。更多信息参见 [Cordova SQLite 的限制](https://github.com/storesafe/cordova-sqlite-storage#other-limitations)。

<!-- EN -->
## Expo

<!-- ZH -->
## Expo

<!-- EN -->
TypeORM is able to run on Expo apps using the [Expo SQLite API](https://docs.expo.io/versions/latest/sdk/sqlite/).

<!-- ZH -->
TypeORM 能够借助 [Expo SQLite API](https://docs.expo.io/versions/latest/sdk/sqlite/) 运行在 Expo 应用上。

<!-- EN -->
## NativeScript

<!-- ZH -->
## NativeScript

<!-- EN -->
1. `tns install webpack` (read below why webpack is required)

<!-- ZH -->
1. `tns install webpack`（为什么需要 webpack 请看下面）

<!-- EN -->
2. `tns plugin add nativescript-sqlite`

<!-- ZH -->
2. `tns plugin add nativescript-sqlite`

<!-- EN -->
3. Create a DataSource in your app's entry point

<!-- ZH -->
3. 在应用的入口点创建一个 DataSource

<!-- EN -->
   ```typescript
import driver from "nativescript-sqlite"

const dataSource = new DataSource({
    database: "test.db",
    type: "nativescript",
    driver,
    entities: [
        Todo, //... whatever entities you have
    ],
    logging: true,
})
   ```

<!-- ZH -->
   ```typescript
import driver from "nativescript-sqlite"

const dataSource = new DataSource({
    database: "test.db",
    type: "nativescript",
    driver,
    entities: [
        Todo, //... 你的任何实体
    ],
    logging: true,
})
   ```

<!-- EN -->
Note: This works only with NativeScript 4.x and above

<!-- ZH -->
注意：这仅适用于 NativeScript 4.x 及以上版本

<!-- EN -->
*When using with NativeScript, **using webpack is compulsory**. The `typeorm/browser` package is raw ES7 code with `import/export` which will **NOT** run as it is. It has to be bundled. Please use the `tns run --bundle` method*

<!-- ZH -->
*与 NativeScript 一起使用时，**必须使用 webpack**。`typeorm/browser` 包是带 `import/export` 的原始 ES7 代码，它 **无法** 直接运行，必须被打包。请使用 `tns run --bundle` 方式*

<!-- EN -->
Checkout example [here](https://github.com/championswimmer/nativescript-vue-typeorm-sample)!

<!-- ZH -->
在[这里](https://github.com/championswimmer/nativescript-vue-typeorm-sample)查看示例！

<!-- EN -->
## React Native

<!-- ZH -->
## React Native

<!-- EN -->
TypeORM is able to run on React Native apps using the [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage) plugin.

<!-- ZH -->
TypeORM 能够借助 [react-native-sqlite-storage](https://github.com/andpor/react-native-sqlite-storage) 插件运行在 React Native 应用上。
