title: How to fix SyntaxError: Cannot use import statement outside a module?
body: <p>I am new to all of this, and I'm trying to add Node + Typescript backend to my Angular project. But after importing express I always get the error.</p>
  <pre><code>[ERROR] SyntaxError: Cannot use import statement outside a module.
  </code></pre>
  <h3>package.json</h3>
  <pre><code>{
    &quot;name&quot;: &quot;server&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;type&quot;: &quot;module&quot;,
    &quot;scripts&quot;: {
      &quot;serve&quot;: &quot;ts-node-dev server.ts&quot;,
      &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
    },
    &quot;author&quot;: &quot;&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;dependencies&quot;: {
      &quot;@types/express&quot;: &quot;^4.17.11&quot;,
      &quot;express&quot;: &quot;^4.17.1&quot;,
      &quot;ts-node&quot;: &quot;^9.1.1&quot;,
      &quot;ts-node-dev&quot;: &quot;^1.1.6&quot;,
      &quot;tslint&quot;: &quot;^6.1.3&quot;,
      &quot;typescript&quot;: &quot;^4.2.4&quot;
    },
  }
  </code></pre>
  <h3>tsconfig.json</h3>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      &quot;target&quot;: &quot;ESNEXT&quot;,                                
      &quot;module&quot;: &quot;commonjs&quot;, 
      &quot;strict&quot;: false, 
      &quot;esModuleInterop&quot;: true, 
      &quot;skipLibCheck&quot;: true,                          
      &quot;forceConsistentCasingInFileNames&quot;: true        
    }
  }   
  </code></pre>
  <h3>server.ts</h3>
  <pre><code>import * as express from 'express';
  
  const app = express();
  
  app.listen(4201, '127.0.0.', function() {
    console.log('Server is listening on port 4201');
  });
  </code></pre>
  <p>I have looked this up and the most common solution was to add &quot;type&quot;: &quot;module&quot; to package.json which I did. I also know that this works only from Node 13 and further, and I have Node: 14.15.5.</p>