score:0
if you are building something like blog or Ecomm site you are storing img in a folder.
my img is inside upload/pic.png upload is my folder where I am storing img
Transfer your img folder or img to Public folder
access
img in .js FILE
<img src={ process.env.PUBLIC_URL`/uploads/pic.png} />
<img src={ process.env.PUBLIC_URL`/uploads/${this.props.data.postImage}`} />
img in .HTML
<img src = '%PUBLIC_URL%pic.png'/>
read about file processed by
webPack
score:1
I've seen this exact error in an image src require. It's thrown when the pass-in is undefined, which in your case is book.cover
. Essentially it wants to set the source as an undefined link. That ./
is implied.
Consider conditional rendering with a typeof
check to ensure that the image tag does not load if the cover does not exist.
if (typeof(book.cover) !== 'undefined') {
return ( <img src={require(`../images/${book.cover}`)} /> );
} else {
// error handling here
...
}
Source: stackoverflow.com
Related Query
- cant add image in react getting an error Error: Cannot find module './undefined' when using require
- React Native Error Cannot find module 'metro-config/src/defaults/blacklist'
- Tailwind in React project - getting "Cannot find module 'autoprefixer'" error during setup
- getting error : Could not find a declaration file for module 'react-bootstrap-modal'. in react js
- react storybook jest snapshots leads to an error Cannot find module '../../package' from 'node.js'
- Create React App Error - Loading PostCSS "postcss-preset-env" plugin failed: Cannot find module 'node:vm'
- Cannot find module './assets/photo.jpg' error in React
- React component: getting Syntax error: Cannot read properties of undefined (reading 'map') (0:undefined) when trying to add function to my code
- Error in production build with Webpack, Babel and React - Error: Cannot find module '@babel/runtime/core-js/get-iterator'
- Cannot find module whenever I add another component to React JS
- Console error "Uncaught Error: Cannot find module "/axios" at webpackMissingModule" with react
- React - cant find module - trying to pass cell image path variable
- Cannot set property 'color' of undefined getting this error in React
- Error when importing image dynamically: "Error: Cannot find module './asset/<imageName>.jpg'"
- Im getting the error message Cannot read properties of undefined (reading 'product') in React
- I'm getting an error in React while connecting it to the firebase "Could not find module in path: 'firebase' relative to '/src/firebase-config.js'"
- i get this error Error: Cannot find module '../list/songQueue.jpg' ,using json-server i am passing path of my image file
- Getting `Cannot find module '.next\server\pages-manifest.json'` error when trying to add `babel.config.js` in nextjs app
- getting the error Cannot read property 'value' of undefined in react while using arrow function
- Getting an error TypeError: Cannot read property 'map' of undefined in React
- ERROR in Cannot find module 'babel-core'. using react.js, webpack, and express server
- Cannot find namespace 'ctx' error when creating Context with react - typescript
- After $npm install, Getting Error: Cannot find module '../lib/utils/unsupported.js'
- Cannot find module 'caniuse-lite/dist/unpacker/agents' when running create react app
- Cannot find module '@babel/plugin-transform-react-jsx-source' when running React App
- Create react app Error: Cannot find module './locale'
- Cannot find module 'react-dev-utils/crossSpawn' exception React App
- Dealing with "Failed to load plugin 'react' declared in '.eslintrc': Cannot find module 'eslint-plugin-react'" ESLint error
- React & Jest: Cannot find module from test file
- Jest fails Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js' after React 16 upgrade
More Query from same tag
- How do I asynchronously get JSON schema through an API call in react-crud-admin library?
- Get Mongoose validation error message in React
- Dealing with cursor with controlled contenteditable in React
- setState in multiple fetch requests
- Passing a parameter from child to parent using prop callback
- react-google-maps fitBounds and panToBounds does not scale the map
- How to fetch from backend database to display on frontend using react?
- Any better way to pass data from a child component to a function in a parent component without using bind()?
- i18next-react and custom format
- AntD React: Disable time ranges for specific dates in DateRangePicker
- Module not found: Error: Cannot resolve module 'react-redux'
- URLSearchParams is not defined error when running tests with jest
- How to get progressbar when file upload to browser
- text and icon in a antd button are not aligned vertically
- How undo setState if Fecth was failed?
- Unable to load images dynamically in react app
- React: Uncaught TypeError: Cannot read property 'name' of undefined in mapStateToProps
- array value is undefined … how do I test for that
- How to Serve a React App with Django on Elastic Beanstalk?
- How to optimize code in repeated conditional rendering?
- Is It Possible to Style React Components After Creation?
- react-draggable not working with custom components
- How to get the cumulated height from children elements within a parent component
- Using React, how do you pass a function from a parent component to a child component and run it in the useEffect hook?
- Why I'm not getting back the new value of useState - React.JS?
- How can I display an array of objects inside a object in React?
- className not populated in Gatsby with Bulma
- Why i can't call method in subscribe - Cannot read property 'showMessageFromSocket' of undefined
- Why not use Object.prototype.toString() to check plain object in redux?
- is useCallback a performance boost for the react app?