title: Node Error: Cannot use import statement outside a module even though I'm not
body: <p>I am using Pm2 and this is the error:</p>
  <pre><code>SyntaxError: Cannot use import statement outside a module
  
  Warning: To load an ES module, set &quot;type&quot;: &quot;module&quot; in the package.json or use the .mjs extension.
  </code></pre>
  <p>The issue is, the <code>package.json</code> is already set to <code>&quot;type&quot;: &quot;module&quot;</code>.</p>
  <p>Also, everything used to work fine until I restart the server.</p>
  <p>Here is the actual <code>.js</code> file:</p>
  <pre><code>const http = require('http');
  const url = require('url');
  const querystring = require('querystring');
      
  const hostname = 'localhost';
  const port = 8080;
      
  import captureWebsite from 'capture-website';
  
  
  const server = http.createServer((req, res) =&gt; {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello World!\n');
      
      ....
  });
  </code></pre>