-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Closed
Copy link
Labels
Description
Issue description
Trying to import DataSource in a NextJS client component breaks with BSON typing import
Expected Behavior
To be able to import the datasource without issues
Actual Behavior
Fails with:
error - ./node_modules/typeorm/browser/driver/mongodb/bson.typings.js
Module parse failed: Export 'BSON' is not defined (1:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> export { BSON };
|
| //# sourceMappingURL=bson.typings.js.map
Import trace for requested module:
./node_modules/typeorm/browser/driver/mongodb/bson.typings.js
./node_modules/typeorm/browser/driver/mongodb/typings.js
./node_modules/typeorm/browser/index.js
./src/app/page.tsx
Steps to reproduce
- Create new project with
yarn create next-app - Install typeorm with
yarn add typeorm - Open
src/app/page.tsxand add the following:
'use client';
import "reflect-metadata";
import { DataSource } from "typeorm/browser";
export async function initDB(database: Uint8Array) {
const datasource = new DataSource({
type: 'sqljs',
synchronize: false,
database,
logging: true,
autoSave: true,
entities: [],
subscribers: [],
migrations: [],
});
await datasource.initialize();
return datasource;
}
No need to call the function. This gives the following error:
error - ./node_modules/typeorm/browser/driver/mongodb/bson.typings.js
Module parse failed: Export 'BSON' is not defined (1:9)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> export { BSON };
|
| //# sourceMappingURL=bson.typings.js.map
Import trace for requested module:
./node_modules/typeorm/browser/driver/mongodb/bson.typings.js
./node_modules/typeorm/browser/driver/mongodb/typings.js
./node_modules/typeorm/browser/index.js
./src/app/page.tsx
My Environment
package.json
{
"name": "typeormtest",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@types/node": "18.15.11",
"@types/react": "18.0.37",
"@types/react-dom": "18.0.11",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"next": "13.3.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"typeorm": "^0.3.15", # Also tried with 0.3.14
"typescript": "5.0.4"
}
}
node version: 16.17.0
Additional Context
Seems someone else is getting this issue: https://stackoverflow.com/questions/76025976/typeorm-throws-a-bson-error-in-next-js-app
I'm not selecting any specific driver coz even though I'm trying to use sqljs, the driver failing is the mongo one.
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?
Yes, I have the time, but I don't know how to start. I would need guidance.
awesomedan93, chris-si, Ttou, cahna and ShepelE