I've created a ormconfig.env
file in the nestjs starter project and put the variables from this documentation in there and added this line here
@Module({
imports: [
TypeOrmModule.forRoot(),
TaskModule,
],
})
export class AppModule {
}`
And the console shows this error:
Error: EACCES: permission denied, scandir '/Library/Application Support/Apple/AssetCache/Data' at Object.fs.readdirSync (fs.js:904:18)
How should I properly set up typeorm .env file in nestjs?
I've created a ormconfig.env
file in the nestjs starter project and put the variables from this documentation in there and added this line here
@Module({
imports: [
TypeOrmModule.forRoot(),
TaskModule,
],
})
export class AppModule {
}`
And the console shows this error:
Error: EACCES: permission denied, scandir '/Library/Application Support/Apple/AssetCache/Data' at Object.fs.readdirSync (fs.js:904:18)
How should I properly set up typeorm .env file in nestjs?
Share Improve this question edited Dec 8, 2018 at 17:34 Kim Kern 60.7k20 gold badges218 silver badges214 bronze badges asked Nov 30, 2018 at 16:34 LinkLink 7098 silver badges21 bronze badges2 Answers
Reset to default 6It seems like node is trying to scan your plete file system for entity files and of course does not have the permissions to do so.
Make sure that you have a path within your project folder for the TYPEORM_ENTITIES
variable.
For example, look for all files ending with .entity.ts
recursively under the project's src
folder:
TYPEORM_ENTITIES = src/**/**.entity.ts
I had the same problem as in the question. As the other answer didn't solve my problem, I had to look around. I will leave my solution for those who also have similar troubles with Webpack + TypeORM, as I had.
Here is what I needed to do to make it work.
import { createConnection, getConnectionManager } from "typeorm";
// For hot reload to work need to require files
import { Job } from "../jobs/job.entity";
import { JobAction } from "../jobs/jobaction.entity";
export const databaseProviders = [
{
provide: "DATABASE_CONNECTION",
keepConnectionAlive: true,
useFactory: async () => {
try {
const conn = await createConnection({
...connectionOption,
// add entitities manually
entities: [Job, JobAction],
});
return conn;
} catch (err) {
// If AlreadyHasActiveConnectionError occurs, return already existent connection
if (err.name === "AlreadyHasActiveConnectionError") {
const existentConn = getConnectionManager().get("default");
return existentConn;
}
throw err;
}
},
},
];