import React, { useEffect, useState } from 'react'
import Navbar from './Navbar';
import Cards from './Cards';
const NewsAPI = require('newsapi');
const newsapi = new NewsAPI('apikey');
const Home = () => {
const [news, setNews] = useState();
useEffect(() => {
newsapi.v2.topHeadlines({
sources: 'bbc-news,the-verge',
q: 'bitcoin',
category: 'business',
language: 'en',
country: 'us'
}).then((response: any) => {
setNews(response.articles);
console.log(response.articles);
});
},[])
return (
<>
<Navbar />
<div id='cards'>
{/* code */}
</div>
</>
)
}
export default Home
I am using the electron-react boilerplate. When I try to run this code I am getting these errors :
Cannot GET /index.html
ERROR in ./node_modules/electron/index.js 2:13-28
Module not found: Error: Can't resolve 'path' in '/Users/monke/Stream/frontend/stream-app/node_modules/electron'
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "path": false }
@ ./src/renderer/Home.tsx 36:17-36
@ ./src/renderer/index.tsx 12:31-48
Although if i remove the node js code, the error goes away. Am I not supposed to write the node js code in the component file? If not where am I supposed to write it? If I write it somewhere else how am I supposed to send that information over to the component?