I'm struggling with a weird issue in NestJS + TypeORM.
Pretty much I've created a ManyToMany relation in an entity and, on the owning side of the relation, I've added the @JoinTable() with no parameters.
After running nest build, the entity.js file adds a new import const browser_1 = require("typeorm/browser");
, which, I found out, is used in declaring the JoinTable option in the compiled JS file => browser_1.JoinTable()
.
The issue is that, when using typeorm to generate a new migration file, I keep getting the following error:
import { __awaiter, __generator } from "tslib";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.require.extensions.<computed> [as .js] (C:XXXXXXdevXXXpistis-api
ode_moduless-nodesrcindex.ts:1045:43)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:XXXXXXdevXXXpistis-apidistmodulescollaboratorentitycollaborator.entity.js:17:19)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
Tracking down the issue, it seems to be related to this browser import that is being imported from ./node_modules/typeorm/browser/index.js
I'm using .env to configure typeorm, with the following:
TYPEORM_CONNECTION=postgres
TYPEORM_HOST=localhost
TYPEORM_USERNAME=xxxxx
TYPEORM_PASSWORD=xxxxx
TYPEORM_DATABASE=xxxx
TYPEORM_PORT=5432
TYPEORM_SYNCHRONIZE=false
TYPEORM_LOGGING=true
TYPEORM_DROP_SCHEMA=false
TYPEORM_MIGRATIONS_RUN=true
TYPEORM_ENTITIES=dist/modules/**/entity/*.js
TYPEORM_ENTITIES_DIR=src/modules/**/entity
TYPEORM_MIGRATIONS=dist/migrations/*.js
TYPEORM_MIGRATIONS_DIR=src/migrations
TYPEORM_MIGRATIONS_TABLE_NAME='orm_migrations'
This configuration has worked until I've introduced the ManyToMany relation and the JoinTable.
As far as .tsconfig goes, I have:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"dom",
"es6",
"dom.iterable",
"esnext"
],
"allowJs": true,
"declaration": true,
"removeComments": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
},
"include": [
"src"
]
}
Any help would be appreciated.
Thanks in advance!
question from:
https://stackoverflow.com/questions/65833563/issue-with-jointable-in-nestjs-typeorm