typeorm: Export 'BSON' is not defined

Issue description

Export ‘BSON’ is not defined in electron app with vite and typescript

Expected Behavior

Looks related to this issue and fix

Still seeing this issue on 0.3.17, but rather than nextjs, this is an electron app (using electron forge vite-typescript template) and SQLite. Trying to import and use typeorm entities within main.ts electron app process

Actual Behavior

Seeing this error

[commonjs--resolver] Export 'BSON' is not defined (1:9) in /PROJECT/desktop/node_modules/typeorm/browser/driver/mongodb/bson.typings.js
file: /PROJECT/desktop/node_modules/typeorm/browser/driver/mongodb/bson.typings.js:1:9
1: export { BSON };

when doing the following in main.ts

import { entities } from "./entities"

where entities is an array of TypeORM entities

with datasource that looks like

import "reflect-metadata"
import * as TypeOrm from "typeorm"
import { entities } from "./entities"

export const DataSource = new TypeOrm.DataSource({
    type: "sqlite",
    database: "./db.sqlite",
    synchronize: true,
    logging: false,
    entities: entities,
    migrations: [],
    subscribers: [],
})

Steps to reproduce

Repo reproducing the issue is here

My Environment

Electron, vite, typescript,

dependencies: {
  "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "reflect-metadata": "^0.1.13",
    "sqlite3": "^5.0.2",
    "typeorm": "0.3.17",
    "utf-8-validate": "^5.0.10"
  },
  "devDependencies": {
    "@electron-forge/cli": "^6.4.2",
    "@electron-forge/maker-deb": "^6.4.2",
    "@electron-forge/maker-rpm": "^6.4.2",
    "@electron-forge/maker-squirrel": "^6.4.2",
    "@electron-forge/maker-zip": "^6.4.2",
    "@electron-forge/plugin-auto-unpack-natives": "^6.4.2",
    "@electron-forge/plugin-vite": "^6.4.2",
    "@types/electron": "^1.6.10",
    "@types/node": "^20.4.7",
    "@types/react": "^18.2.15",
    "@types/react-dom": "^18.2.7",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "@vitejs/plugin-react-swc": "^3.3.2",
    "autoprefixer": "^10.4.15",
    "electron": "26.2.1",
    "eslint": "^8.0.1",
    "eslint-plugin-import": "^2.25.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.3",
    "ts-node": "^10.0.0",
    "typescript": "~4.5.4"
  }

Additional Context

N/a

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Reactions: 2
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Following https://github.com/typeorm/typeorm/issues/9959, I can confirm that downgrading to v0.3.14 fixes the issue.