title: npm + Typescript: Cannot use import statement outside a module
body: <p>I wrote a package and published it to npm. The package starts with</p>
  <pre><code>import * as aws from &quot;@pulumi/aws&quot;;
  import * as pulumi from &quot;@pulumi/pulumi&quot;;
  
  export interface ...
  export class controlplaneDependencies extends pulumi.ComponentResource {
  ...
  </code></pre>
  <p>The publishing and installation works fine. When I try to run the code from a different <code>index.ts</code>, it fails with the error</p>
  <pre><code>import * as aws from &quot;@pulumi/aws&quot;;
      ^^^^^^
      
      SyntaxError: Cannot use import statement outside a module
          at compileFunction (&lt;anonymous&gt;)
          at Object.compileFunction (node:vm:353:18)
          at wrapSafe (node:internal/modules/cjs/loader:1039:15)
          at Module._compile (node:internal/modules/cjs/loader:1073:27)
          at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
          at Object.require.extensions.&lt;computed&gt; [as .ts] (/Users/cinto/public-cloud-operator/tests/aws/node_modules/ts-node/src/index.ts:431:14)
          at Module.load (node:internal/modules/cjs/loader:989:32)
          at Function.Module._load (node:internal/modules/cjs/loader:829:14)
          at Module.require (node:internal/modules/cjs/loader:1013:19)
          at require (node:internal/modules/cjs/helpers:93:18)
  
  </code></pre>
  <p>This is how I am calling the package</p>
  <pre><code>import * as controlplane from &quot;@bb/controlplane&quot;;
  
  stackOutput=new controlplane.controlplaneDependencies(&quot;Install dependencies&quot;, {
         Provider: awsProvider,
  </code></pre>
  <p>I am not sure how to fix this. I tried adding <code>&quot;type&quot;: &quot;module&quot;,</code> but is still fails.</p>
  <p>I also tried</p>
  <pre><code>const aws = require( &quot;@hybrid-cloud/aws&quot; )
  </code></pre>
  <p>but then <code>aws</code> cannot be accessed inside the interface.</p>
  <p>Any pointers are helpful. Here is the <code>tsconfig.json</code></p>
  <pre><code>
  {
    &quot;compilerOptions&quot;: {
      &quot;strict&quot;: true,
      &quot;strictPropertyInitialization&quot;: false,
      &quot;target&quot;: &quot;ES6&quot;,
      &quot;module&quot;: &quot;CommonJS&quot;,
      &quot;moduleResolution&quot;: &quot;Node&quot;,
      &quot;sourceMap&quot;: true,
      &quot;declaration&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;pretty&quot;: true,
      &quot;noFallthroughCasesInSwitch&quot;: true,
      &quot;noImplicitReturns&quot;: true,
      &quot;noImplicitAny&quot;: true,
      &quot;forceConsistentCasingInFileNames&quot;: true,
      &quot;resolveJsonModule&quot;: true,
      &quot;lib&quot;: [
        &quot;es2019&quot;,
        &quot;es5&quot;,
        &quot;es6&quot;,
        &quot;dom&quot;,
        &quot;es2015.collection&quot;
      ],
      &quot;outDir&quot;: &quot;./bin&quot;
    },
    &quot;exclude&quot;: [
      &quot;node_modules&quot;
    ]
  }
  </code></pre>