title: How to use ts-node ESM with node modules?
body: <p>Note: I am aware that the following question is about an experimental feature. I have created a <a href="https://github.com/TypeStrong/ts-node/discussions/1321" rel="noreferrer">clone on the ts-node discussion forum</a>. However, I believe StackOverflow has a wider exposure and would lead to a solution in less time.</p>
  <p>I am trying to make a simple script that reads a file from one location and processes it. Here is what I have so far, having followed <a href="https://github.com/TypeStrong/ts-node/issues/1007" rel="noreferrer">#1007</a>:</p>
  <p>Node: v12.22.1</p>
  <pre><code>my-app
  ├── .eslintrc.cjs
  ├── .gitignore
  ├── in
  │   └── given.txt
  ├── node_modules
  ├── out
  ├── package-lock.json
  ├── package.json
  ├── src
  │   ├── helper.ts
  │   └── main.ts
  └── tsconfig.json
  </code></pre>
  <p>package.json</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;name&quot;: &quot;my-app&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;type&quot;: &quot;module&quot;,
    &quot;scripts&quot;: {
      &quot;lint&quot;: &quot;eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings=0&quot;,
      &quot;start&quot;: &quot;node --experimental-specifier-resolution=node --experimental-modules --no-warnings --loader ts-node/esm ./src/main.ts&quot;
    },
    &quot;author&quot;: &quot;Kaustubh Badrike&quot;,
    &quot;devDependencies&quot;: {
      &quot;@types/node&quot;: &quot;^15.3.0&quot;,
      &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.24.0&quot;,
      &quot;@typescript-eslint/parser&quot;: &quot;^4.24.0&quot;,
      &quot;eslint&quot;: &quot;^7.26.0&quot;,
      &quot;ts-node&quot;: &quot;^9.1.1&quot;,
      &quot;typescript&quot;: &quot;^4.2.4&quot;
    }
  }
  </code></pre>
  <p>tsconfig.json</p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;target&quot;: &quot;es5&quot;,                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
      &quot;module&quot;: &quot;ESNext&quot;,                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
      
      /* Strict Type-Checking Options */
      &quot;strict&quot;: true,                                 /* Enable all strict type-checking options. */
      
      /* Module Resolution Options */
      &quot;moduleResolution&quot;: &quot;node&quot;,                  /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
      &quot;esModuleInterop&quot;: true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
      
      /* Advanced Options */
      &quot;skipLibCheck&quot;: true,                           /* Skip type checking of declaration files. */
      &quot;forceConsistentCasingInFileNames&quot;: true        /* Disallow inconsistently-cased references to the same file. */
    }
  }
  </code></pre>
  <p>main.ts</p>
  <pre class="lang-js prettyprint-override"><code>import { readFileSync } from &quot;fs&quot;;
  
  const contents = readFileSync('../in/given.txt');
  </code></pre>
  <p>However, when I try <code>npm run start</code>, I get the following</p>
  <pre><code>TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected string to be returned for the &quot;format&quot; from the &quot;loader getFormat&quot; function but got type 
  object.
      at Loader.getFormat (internal/modules/esm/loader.js:125:13)
      at Loader.getModuleJob (internal/modules/esm/loader.js:247:20)
      at ModuleWrap.&lt;anonymous&gt; (internal/modules/esm/module_job.js:49:17)
      at async Promise.all (index 0)
      at link (internal/modules/esm/module_job.js:53:9)
  </code></pre>
  <p>The error does not occur if I remove the import from fs. Importing items from helper.ts works as well.</p>
  <p><strong>What do I need to do to get it to work?</strong></p>