2

Im making a simple typescript project, but can't manage to solve the following error:

Compiled with problems: ERROR in ./src/index.tsx 7:0-28 Module not found: Error: Can't resolve './App' in '/Projects/test/src'

Any suggestions??

Here's the files..

Home:

import React from "react"

export const Home = () => {
    return (
        <>
            <div>
                <p>Essa é a pagina home</p>
            </div>
        </>
    );
};

export default Home;

App.tsx:

import React from 'react';
import { Home } from './pages/Home';

export function App() {
  return (
      <Home />
  );
};

index.tsx:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import { App } from './App';

const ApplicationWrapper = () => {
  return (
    <App />
  );
};

ReactDOM.render(
  <React.StrictMode>
    <ApplicationWrapper />
  </React.StrictMode>,
  document.getElementById('main'),
);

FILE STRUCTURE:

File Structure

3 Answers 3

1

When the code is exported and with a default keyword, that means you only can import by using import Alias from './module'. If you want to import through Object Destructuring, it needs to export a Component or module without using the default keyword.

Last line of Home component.

export { Home };

When it needs to import.

import { Home } from './path-to-component';
Sign up to request clarification or add additional context in comments.

Comments

0

you can export once at Home component like this:

import React from "react"

const Home = () => {
    return (
        <>
            <div>
                <p>Essa é a pagina home</p>
            </div>
        </>
    );
};

export default Home;

1 Comment

I removed the other export, applied ur suggestion but still have the same problem.
0

Please check, App.tsx file should be in index.tsx folder. ie both files should be in /Projects/test/src folder.

3 Comments

Both are already placed inside src folder :/ I update the thread with another print of my files structure
Can you check once replacing <App /> in index.tsx file with <div>test</div>. If it is working then issue in imports, otherwise there is issue in the app configuration.
It worked! But I couldn't manage to solve the import issue..

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.