title: TypeORM Migration: File must contain a TypeScript / JavaScript code and export a DataSource instance
body: <p>When trying to autogenerate migrations I get the following error.</p>
  <p>File must contain a TypeScript / JavaScript code and export a DataSource instance</p>
  <p>This is the command that I am running:</p>
  <pre class="lang-js prettyprint-override"><code>typeorm migration:generate projects/core/migrations/user -d db_config.ts -o
  </code></pre>
  <p>And my db_config.ts file looks like this:</p>
  <pre class="lang-js prettyprint-override"><code>import { DataSource } from &quot;typeorm&quot;;
  
  const AppDataSource = new DataSource({
    type: &quot;postgres&quot;,
    host: process.env.PGHOST,
    port: 5432,
    username: process.env.PGUSER,
    password: process.env.PGPASSWORD,
    database: process.env.PGDATABASE,
    entities: [&quot;./projects/**/entities/*.ts&quot;],
    migrations: [&quot;./projects/**/migrations/**.js&quot;],
    synchronize: true,
    logging: false,
  }); 
  
  export default AppDataSource
  </code></pre>
  <p>My current file structure looks like this:</p>
  <ul>
  <li>back_end
  -- projects
  --- index.ts
  --- db_config.ts</li>
  </ul>
  <p>And my index.ts file looks like this:</p>
  <pre class="lang-js prettyprint-override"><code>import express from &quot;express&quot;;
  import { AppDataSource } from &quot;./data-source&quot;;
  import budget_app from &quot;./projects/budget_app/routes&quot;;
  
  export const app = express();
  const port = 3000;
  
  AppDataSource.initialize()
    .then(() =&gt; {
      console.log(&quot;Data Source has been initialized!&quot;);
    })
    .catch((err) =&gt; {
      console.error(&quot;Error during Data Source initialization&quot;, err);
    });
  
  // export default AppDataSource;
  
  app.get(&quot;/&quot;, (req, res) =&gt; {
    res.send(&quot;Hello World!!!!&quot;);
  });
  
  app.use(&quot;/budget_app&quot;, budget_app);
  
  app.listen(port, () =&gt; {
    console.log(`Example app listening on port ${port}`);
  });
  </code></pre>
  <p>I am also running this in a docker container along with my postgres database. I have confirmed that the connection works because if I do synchronize=true it will create the table just fine. I just can't create the migration.</p>
  <p>So I'm confused and don't know where to go from here to fix the issue. Thanks for your help in advance!</p>