title: Ts-node : SyntaxError: Cannot use import statement outside a module
body: <p>I was trying to use the top level in the project and saw that it was necessary to change the module from tscofnig to esnext or system, but for some reason my ts-node's error.
  And I already put the type: module I tried to use the flag: --experimental-modules but the error still does not know how to solve.</p>
  <p>package.json:</p>
  <pre><code>{
    &quot;name&quot;: &quot;micro-hr&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;license&quot;: &quot;MIT&quot;,
    &quot;type&quot;: &quot;module&quot;,
    &quot;scripts&quot;: {
      &quot;commit&quot;: &quot;git-cz&quot;,
      &quot;build&quot;: &quot;babel src --extensions \&quot;.js,.ts\&quot; --out-dir dist --copy-files --no-copy-ignored&quot;,
      &quot;start:dev&quot;: &quot;ts-node-dev --experimental-modules --inspect --respawn --transpile-only --ignore-watch node_modules -r tsconfig-paths/register src/index.ts&quot;,
      &quot;start:debug&quot;: &quot;node start --debug --watch&quot;,
      &quot;start:prod&quot;: &quot;node dist/index.ts&quot;,
      &quot;test&quot;: &quot;jest&quot;,
      &quot;lint&quot;: &quot;eslint --fix&quot;,
      &quot;lint2&quot;: &quot;eslint \&quot;{src,apps,libs,test}/**/*.ts\&quot; --fix&quot;,
      &quot;typeorm&quot;: &quot;ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config ./ormconfig.ts&quot;,
      &quot;migration:generate&quot;: &quot;ts-node ./node_modules/typeorm/cli.js migration:generate -n&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@babel/cli&quot;: &quot;^7.11.5&quot;,
      &quot;@babel/core&quot;: &quot;^7.11.5&quot;,
      &quot;@babel/node&quot;: &quot;^7.10.5&quot;,
      &quot;@babel/preset-env&quot;: &quot;^7.11.5&quot;,
      &quot;@babel/preset-typescript&quot;: &quot;^7.10.4&quot;,
      &quot;@commitlint/cli&quot;: &quot;^9.1.2&quot;,
      &quot;@commitlint/config-conventional&quot;: &quot;^9.1.2&quot;,
      &quot;@types/bcryptjs&quot;: &quot;^2.4.2&quot;,
      &quot;@types/cookie-parser&quot;: &quot;^1.4.2&quot;,
      &quot;@types/cors&quot;: &quot;^2.8.7&quot;,
      &quot;@types/express&quot;: &quot;^4.17.8&quot;,
      &quot;@types/helmet&quot;: &quot;^0.0.48&quot;,
      &quot;@types/jest&quot;: &quot;^26.0.13&quot;,
      &quot;@types/node&quot;: &quot;^14.6.4&quot;,
      &quot;@types/pino&quot;: &quot;^6.3.0&quot;,
      &quot;@types/pino-http&quot;: &quot;^5.0.5&quot;,
      &quot;@types/supertest&quot;: &quot;^2.0.10&quot;,
      &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.0.1&quot;,
      &quot;@typescript-eslint/parser&quot;: &quot;^4.0.1&quot;,
      &quot;babel-plugin-module-resolver&quot;: &quot;^4.0.0&quot;,
      &quot;commitizen&quot;: &quot;^4.2.1&quot;,
      &quot;cz-conventional-changelog&quot;: &quot;^3.3.0&quot;,
      &quot;eslint&quot;: &quot;^7.8.1&quot;,
      &quot;eslint-config-airbnb-base&quot;: &quot;^14.2.0&quot;,
      &quot;eslint-config-prettier&quot;: &quot;^6.11.0&quot;,
      &quot;eslint-config-standard&quot;: &quot;^14.1.1&quot;,
      &quot;eslint-import-resolver-typescript&quot;: &quot;^2.3.0&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.22.0&quot;,
      &quot;eslint-plugin-node&quot;: &quot;^11.1.0&quot;,
      &quot;eslint-plugin-prettier&quot;: &quot;^3.1.4&quot;,
      &quot;eslint-plugin-promise&quot;: &quot;^4.2.1&quot;,
      &quot;eslint-plugin-standard&quot;: &quot;^4.0.1&quot;,
      &quot;husky&quot;: &quot;^4.2.5&quot;,
      &quot;jest&quot;: &quot;^26.4.2&quot;,
      &quot;pino-pretty&quot;: &quot;^4.2.0&quot;,
      &quot;prettier&quot;: &quot;^2.1.1&quot;,
      &quot;supertest&quot;: &quot;^4.0.2&quot;,
      &quot;ts-jest&quot;: &quot;^26.3.0&quot;,
      &quot;ts-node&quot;: &quot;^9.0.0&quot;,
      &quot;ts-node-dev&quot;: &quot;^1.0.0-pre.62&quot;,
      &quot;tsconfig-paths&quot;: &quot;^3.9.0&quot;,
      &quot;tscpaths&quot;: &quot;^0.0.9&quot;,
      &quot;typescript&quot;: &quot;^4.0.2&quot;
    },
    &quot;dependencies&quot;: {
      &quot;amqplib&quot;: &quot;^0.6.0&quot;,
      &quot;assert&quot;: &quot;^2.0.0&quot;,
      &quot;bcryptjs&quot;: &quot;^2.4.3&quot;,
      &quot;class-transformer&quot;: &quot;^0.3.1&quot;,
      &quot;cors&quot;: &quot;^2.8.5&quot;,
      &quot;dotenv&quot;: &quot;^8.2.0&quot;,
      &quot;envalid&quot;: &quot;^6.0.2&quot;,
      &quot;express&quot;: &quot;^4.17.1&quot;,
      &quot;extendable-error&quot;: &quot;^0.1.7&quot;,
      &quot;helmet&quot;: &quot;^4.1.0&quot;,
      &quot;nabbitmq&quot;: &quot;^1.0.0&quot;,
      &quot;pg&quot;: &quot;^8.3.3&quot;,
      &quot;pino&quot;: &quot;^6.5.1&quot;,
      &quot;pino-http&quot;: &quot;^5.2.0&quot;,
      &quot;reflect-metadata&quot;: &quot;^0.1.13&quot;,
      &quot;spt-rabbit-helpers&quot;: &quot;^1.0.6&quot;,
      &quot;tsyringe&quot;: &quot;^4.3.0&quot;,
      &quot;typeorm&quot;: &quot;^0.2.25&quot;
    },
    &quot;config&quot;: {
      &quot;commitizen&quot;: {
        &quot;path&quot;: &quot;cz-conventional-changelog&quot;
      }
    }
  }
  </code></pre>
  <p>tsconfig:</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;target&quot;: &quot;es2020&quot;,
      &quot;module&quot;: &quot;esnext&quot;,
      &quot;allowJs&quot;: true,
      &quot;outDir&quot;: &quot;./dist&quot;,
      &quot;rootDir&quot;: &quot;./src&quot;,
      &quot;strict&quot;: true,
      &quot;strictPropertyInitialization&quot;: false,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;baseUrl&quot;: &quot;./src&quot;,
      &quot;allowSyntheticDefaultImports&quot;: true,
      &quot;esModuleInterop&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;emitDecoratorMetadata&quot;: true,
      &quot;forceConsistentCasingInFileNames&quot;: true,
      &quot;noImplicitAny&quot;: true,
      &quot;typeRoots&quot;: [&quot;node_modules/@types&quot;, &quot;@types&quot;]
    },
    &quot;include&quot;: [&quot;src&quot;, &quot;__tests__&quot;],
    &quot;exclude&quot;: [&quot;node_modules&quot;]
  }
  </code></pre>
  <p>main:</p>
  <pre><code>import 'reflect-metadata';
  import express from 'express';
  import { RabbitServer } from 'spt-rabbit-helpers';
  import validateEnv from 'utils/validateEnvs';
  import {
    RabbitMqConnectionFactory,
    ConsumerFactory,
    PublisherFactory,
    RabbitMqConnection,
  } from 'nabbitmq';
  import { container, singleton } from 'tsyringe';
  
  const factory = new RabbitMqConnectionFactory();
  factory.setUri('amqp://localhost:5672');
  const ConsumerConnection = await factory.newConnection();
  const PublisherConnection = await factory.newConnection();
  container.registerInstance('Consumer_Connection', ConsumerConnection);
  container.registerInstance('Publisher_Connection', PublisherConnection);
  </code></pre>