Getting error - Building script returned non zero exit code:2

You should not be adding the index.html to your public folder:

Vite should add the correct file to dist automatically. If that’s not happening, this would be a Vite bug and it should be reported there.