Unable to import despite clearly having the file - reactjs

I've been stuck with this error and couldn't fix it even after googling.
it says 'Module not found: Error: Can't resolve'.. based on researching on google, it appears that this happens when the import statement cannot find the file at the declared path.
But there clearly is a file named 'Button.js' in my src/components folder.
I am not sure what is wrong. Would really appreciate your help!

A fix you could do is either exporting Button module as default in the end of Button.js file like
export default Button;
Or either import the button module in braces like :
import { Button} from “./components/Button”
If you haven’t set the base url as src:
As you are using relative paths and /components/Button.js is upper than the page directory so you have to use .. to come out of the pages directory and then read /pages/Home.js
So you should use ../Button.js instead of ./componets/Button.js

try
import {Button} from './components/Button.js'

Related

How should I import components inside the components folder?

I have some files in my components folder. Two of them are CardItem-component/CardItemComponent.js and list-component/list-components.js.
When I'm trying to import the first component into the latter using
import CardItemComponent from "./CardItem-component/CardItemComponent";
it gives the following mistake:
Module not found: Error: Can't resolve './CardItem-component/CardItemComponent' in 'D:\project\src\components\list-component'
import CardItemComponent from "./CardItem-component/CardItemComponent";
Make sure you have given the correct file path and exported the component
export default CardItemComponent
Based on your explanation of your file structure, maybe you are targeting the wrong directory.
import CardItemComponent from "../CardItem-component/CardItemComponent";
I'm guessing your file structure is:
/some-folder
/CardItem-component
CardItemComponent.js
/list-component
list-components.js
When you are importing CardItemComponent.js from list-components.js, you need to go up one directory level to access the /CardItem-component folder, so you will need to prepend your path with ../.
Sorry, it was inattentive me. It works well, I only mistyped a few things.

Word Document Cannot find module or it's corresponding type declarations

I am getting this error trying to import this file from src/assets/documents folder.
I am working on a React Project with Typescript. I am trying to import the file and feed it's value in an anchor tag so it can be downloaded.
When I'm importing images from src/assets/images, this problem is not existing.
Can anyone help?
I had the same problem.
Since you are using TypeScript you will need to define the type of the data you are importing.
The solution is fairly simple you need to create a proxy file which will map the types.
Usually the of the file ends with .d.ts
In Vue for example the convention is shims-vue.d.ts
Click [here][1] to see an example
The content of the fie should be:
declare module '*.doc' {
import nameOfDoc from src/assets/documents (should be your path to the doc)
export default nameOfDoc
}

is there any way to automatically import modules in eslint or vscode?

so I created a consoledata.ts file to log whatever I pass in it as an argument like so:
/* eslint-disable no-console */
export default function ConsoleData(props: any) {
console.log(props);
}
now using the VSCode search icon, I changed every console.log in my code to consoleData since it'll probably take me all day to change them one by one.
now my issue is, the consoleData module is not imported. is there a way I can do this?
There are two ways to auto import in VSCode. The first way is using quick fix. If you are on MacOS, you can do Cmd + . to open the quick fix dialog and then you import the module.
The second option is to use auto import suggestions. They show suggestions as you type. If you are on MacOS, select the function/class you want to import and then you can do Ctrl + Space to open the auto import suggestions dialog.

Cannot find module reactjs

Hi I am new to react I am trying added new component called Test and try to use it the app.js imported test into app.js but still get error. Below you can find stackblitz url Thanks in Advance.
Stackblitz url
import Test from './components/test'
Implement this line, make sure that c is written in lowercase in component/... path OR just copy the line above and replace yours with it. That will work for sure.
Issue in your sandbox is Components whereas your folder name is components:
import Test from './Components';
and you need to complete file path if your not using index.js as reference i.e
import Test from './components/Test';
Here is demo: https://stackblitz.com/edit/react-vcw5a8?file=src%2FApp.js
Two ways to go here: Either you import the File directly like this:
import Test from './components/Test';
or you create a index.jswithin the Components-Folder and add this:
import Test from './test.jsx';
export default Test;
Also, your Import-Statments are Upper-Case whereas you folder-name is lowercase, so you'll have to adjust on or the other.

Not able to import jsx file from the directory, react

Right now bar chart is being displayed by the App.js file, but I want to shift that whole code to Mismatch.jsx file and access it in App.js 's return
I am not able to import mismatch.jsx file to my app.js file
it is giving me following error
ModuleNotFoundError
Could not find module in path: './src/components' relative to '/src/index.js'
https://codesandbox.io/s/react-chartjs-2-5bsbr?file=/src/index.js
Change it to following
import Mismatch from "./container/mismatchdata/mismatch";
Also install bootstrap

Resources