最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set up typeorm .env file? - Stack Overflow

programmeradmin9浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

It 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;
      }
    },
  },
];


发布评论

评论列表(0)

  1. 暂无评论