2

I am a newbie to React. I created a React app which is working fine on npm start. But after npm run build, I am not getting full page info. i.e. I am getting the nav bar but the main content is not available. On the console, the following error is present:

'file:///C:/Users/pkv97/OneDrive/Desktop/ReactJs/CodeWithHarry/TextUtilsHarry/text_utils/build/%E2%80%9Dmanifest.json%E2%80%9D' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

I tried running npm build on D drive as it is searching files on OneDrive but still facing the same issue. On npm build, it should work the same as it is working on npm start.

Can someone guide how to fix it?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
  • 1
    You are opening a local file in the browser that tries to execute an ajax request to some backend. And as the errors says [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is not supported for `file://...` `npm start` most probably create a local http server and you are accessing this file via `http://localhost/....` And that's why it works ... – derpirscher Dec 24 '22 at 08:44
  • how can i fix it?? any solution – Pawan Kumar Dec 24 '22 at 15:59
  • Serve it via a http server ... – derpirscher Dec 24 '22 at 16:06
  • I wonder why you want to do `npm run build`? – Andrew T. Dec 25 '22 at 16:28
  • For deploy my react app i do not want to use npm start every time to load my react app – Pawan Kumar Dec 26 '22 at 08:51

1 Answers1

-3

Re install NPM and Start then it'll work properly.

npm install --save && npm run build
Pranav Choudhary
  • 2,726
  • 3
  • 18
  • 38
eRevolute
  • 9
  • 3