title: Typescript & TypeORM: Cannot use import statement outside a module
body: <p>I've set up a Typescript project with TypeORM and I am facing some issues with the compilation.</p>
  <p>My package structure is like this:</p>
  <pre><code>root
  ├── db
  │   ├── migrations
  │   │   ├── a_migration.ts
  │   ├── connection
  │   │   ├── config.ts &lt;- ormconfig
  │   │   ├── encrypt.ts
  │   │   ├── index.ts &lt;- creates the connection
  ├── src
  │   ├── card
  │   │   ├── entity.ts
  ├── package.json
  ├── tsconfig.json
  </code></pre>
  <p>My config.ts is:</p>
  <pre class="lang-js prettyprint-override"><code>
  export = {
    type: 'postgres',
    host: POSTGRES_HOST,
    port: POSTGRES_PORT,
    username: POSTGRES_USER,
    password: POSTGRES_PASS,
    database: POSTGRES_DB,
    synchronize: true,
    logging: false,
    entities: ['**src/**/*entity.{ts,js}'],
    migrations: ['**/migrations/*.{ts,js}'],
    cli: {
      entitiesDir: 'src/entity',
      migrationsDir: 'db/migrations',
    },
    namingStrategy: new SnakeNamingStrategy(),
  };
  </code></pre>
  <p>tsconfig.json:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;compilerOptions&quot;: {
      &quot;baseUrl&quot;: &quot;.&quot;,
      &quot;target&quot;: &quot;es6&quot;,
      &quot;module&quot;: &quot;CommonJS&quot;,
      &quot;allowJs&quot;: false,
      &quot;esModuleInterop&quot;: true,
      &quot;noImplicitAny&quot;: true,
      &quot;resolveJsonModule&quot;: true,
      &quot;outDir&quot;: &quot;./build&quot;,
      &quot;strict&quot;: true,
      &quot;emitDecoratorMetadata&quot;: true,
      &quot;experimentalDecorators&quot;: true
    },
    &quot;include&quot;: [&quot;./src/*&quot;, &quot;./db/*&quot;],
    &quot;exclude&quot;: [&quot;./**/__tests__/*&quot;, &quot;./**/__functionaltests__/*&quot;]
  }
  </code></pre>
  <p>I tried replacing the <code>**</code> prefix in entities &amp; migrations with a <code>path.join</code> + <code>__dirname</code> but then typeorm could not detect the migration files and the entities. I understand this has something to do with the path resolving where the code ends up under the <code>build</code> folder but I am not sure how I can tackle this.</p>
  <p>If I live it like this the CLI works for the uncompiled code (ts) executing the app with something like <code>nodemon</code> but not for the compiled (js) one.</p>
  <p>The error I am getting from the compiled js is the:
  <code>SyntaxError: Cannot use import statement outside a module</code></p>
  <p>Any help is appreciated, thanks a lot!</p>