title: Using babel with preset-env on a small node project, unable to convert import/export statements to commonjs
body: <p>I'm trying to set up a node project so I can use the common import/export syntax, and for compatibility, use babeljs to convert the <code>import</code> and <code>export</code> statements to <code>require</code>s.</p>
  <p>When I try transpiling using babel though, I'm not seeing any changes and I don't know why.</p>
  <p>Here's my <code>babel.config.js</code></p>
  <pre><code>// babel.config.js
  module.exports = {
    // I thought this was what I would need to add for making the changes, based on the docs
    plugins: [&quot;@babel/plugin-transform-modules-commonjs&quot;],
  
  
    // env takes care of the majority of changes I might need to convert code to make
    // easy to run on a wider range of machines
    presets: [
      [
        &quot;@babel/preset-env&quot;,
        {
          targets: {
            // target an older version where I know there is no ESM support
            node: &quot;10&quot;
          }
        }
      ]
    ],
    // this was in the docs too - I'm not sure if  I need it TBH
    sourceType: &quot;module&quot;
  }
  </code></pre>
  <p>I have a bunch of code using <code>import/export</code>, and <code>async/await</code> in a directory, that I wanted to transpile and put into another directory, <code>lib</code>.</p>
  <p>Here's the command I am using:</p>
  <pre><code>npx babel src --out-dir lib
  
  </code></pre>
  <p>My package.json file online too, and there's nothing too esoteric there. I've tried to follow the documentation faithfully.</p>
  <p>I would expect to see changes in the code to replace the import/export calls with requires in the lib, but no joy.</p>
  <p>What am I doing wrong here? I worked on a related project 6-7 months ago, where I am using babel like this and it <em>does</em> make the changes for me.</p>
  <p>You can see the <a href="https://github.com/thegreenwebfoundation/grid-intensity/tree/ca-fixing-preset-support" rel="nofollow noreferrer">branch with the problem code on github</a>, with the <a href="https://github.com/thegreenwebfoundation/grid-intensity/blob/main/package.json" rel="nofollow noreferrer">package.json</a>, and <a href="https://github.com/thegreenwebfoundation/greentrace-lib" rel="nofollow noreferrer">here's the source code for other project mentioned where it <em>is</em> working</a>.</p>
  <p>Please be gentle, fellow SO commenters - I'm trying my best, I really am.</p>