0

main-layout.tsx

import React from 'react'
import { TLayout } from '@types';
import { Header } from '@common';
    
export function MainLayout({children}:TLayout) {
    return (
       <div>
        {children}
       </div>
      )
    }
    

index.ts

export * from './main-layout'
    

tsconfig.json

"paths": {
    "@layouts"["./components/layouts/index.ts"],
}
    

Terminal

error - ./pages/_app.tsx:5:0
    Module not found: Can't resolve '@layouts'

In my project I can't export from tsx file to ts file, while using ts to export ts can be used normally, how do I fix it?

1 Answer 1

2

When settings the paths you are missing a : between you alias and its paths. It should be:

"@layouts" : ["./components/layouts/index.ts"],

Also make sure in your tsconfig.json that you have added a baseurl property. The most common example is:

    "baseUrl": ".",

Finally, most of the time you want to alias paths to folders rather than files. But that's up to you.

"@layouts" : ["./components/layouts/*"],
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.