title: SyntaxError: Cannot use import statement outside a module
body: <p>I've got an <strong>ApolloServer</strong> project that's giving me trouble, so I thought I might update it and ran into issues when using the latest Babel. My &quot;index.js&quot; is:</p>
  <pre><code>require('dotenv').config()
  import {startServer} from './server'
  startServer()
  </code></pre>
  <p>And when I run it I get the error</p>
  <pre class="lang-none prettyprint-override"><code>SyntaxError: Cannot use import statement outside a module
  </code></pre>
  <p>First I tried doing things to convince TPTB* that this was a module (with no success). So I changed the &quot;<strong>import</strong>&quot; to a &quot;<strong>require</strong>&quot; and this worked.</p>
  <p>But now I have about two dozen &quot;<strong>imports</strong>&quot; in other files giving me the same error.</p>
  <p>*I'm sure the root of my problem is that I'm not even sure what's complaining about the issue. I sort of assumed it was Babel 7 (since I'm coming from Babel 6 and I had to change the presets) but I'm not 100% sure.</p>
  <p>Most of what I've found for solutions don't seem to apply to straight Node. Like this one here:</p>
  <p><em><a href="https://stackoverflow.com/questions/47632562/es6-module-import-giving-uncaught-syntaxerror-unexpected-identifier/47633417#47633417">ES6 module Import giving &quot;Uncaught SyntaxError: Unexpected identifier&quot;</a></em></p>
  <p>Says it was resolved by adding &quot;type=module&quot; but this would typically go in the HTML, of which I have none. I've also tried using my project's old presets:</p>
  <pre><code>&quot;presets&quot;: [&quot;es2015&quot;, &quot;stage-2&quot;],
  &quot;plugins&quot;: []
  </code></pre>
  <p>But that gets me another error: &quot;Error: Plugin/Preset files are not allowed to export objects, only functions.&quot;</p>
  <p>Here are the dependencies I started with:</p>
  <pre><code>&quot;dependencies&quot;: {
  &quot;@babel/polyfill&quot;: &quot;^7.6.0&quot;,
  &quot;apollo-link-error&quot;: &quot;^1.1.12&quot;,
  &quot;apollo-link-http&quot;: &quot;^1.5.16&quot;,
  &quot;apollo-server&quot;: &quot;^2.9.6&quot;,
  &quot;babel-preset-es2015&quot;: &quot;^6.24.1&quot;,
  </code></pre>