title: Module not found with corresponding type declarations using Typescript with Next.js
body: <p>I have a next.js project that I am trying to add typescript to.</p>
  <p>My folder structure is as follows:</p>
  <pre><code>api
    aggregation.ts
  interfaces
    index.ts
  components
    Component1
      index.js
      index.module.css
    Component2
      index.js
      index.module.css
  pages
    page1
      index.js
      index.module.css
  </code></pre>
  <p>I have an alias for <code>interfaces</code> in <code>next.config.js</code></p>
  <pre><code>config.resolve.alias.interfaces = path.join(__dirname, 'interfaces');
  </code></pre>
  <p><strong>Now the actual issue</strong></p>
  <p><code>index.ts</code> in <code>interfaces</code> exports interfaces such as</p>
  <pre><code> export interface Order {
    store: Store;
    orderNumber: string;
    totals: Totals;
    customer: Customer;
    currency: Currency;
    paymentMethod: PaymentMethod;
    items: OrderProduct[];
    createdAt: string;
    orderId: string;
  }
  </code></pre>
  <p>And I'm trying to import them into <code>aggregation.ts</code> like</p>
  <pre><code>import { Order } from 'interfaces';
  </code></pre>
  <p>And am getting</p>
  <pre><code>Cannot find module 'interfaces' or its corresponding type declarations.
  </code></pre>
  <p>Which is also causing the builds to fail.</p>
  <p>I have installed</p>
  <pre><code>&quot;@types/node&quot;: &quot;^16.0.1&quot;,
  &quot;@types/react&quot;: &quot;^17.0.14&quot;,
  &quot;typescript&quot;: &quot;^4.3.5&quot;,
  </code></pre>
  <p>And next has generated <code>next-env.d.ts</code> correctly with</p>
  <pre><code>/// &lt;reference types=&quot;next&quot; /&gt;
  /// &lt;reference types=&quot;next/types/global&quot; /&gt;
  </code></pre>
  <p>Any ideas on how to fix the <code>Cannot find module</code> issue? I have a feeling it may have something to do with my folder structure or my build step. But I am also getting syntax highlighting indicating the import errors so it is probable typescript config related.</p>
  <p>Any advice would be appreciated!</p>