Vite React Simple Project Getting Build error script returned non-zero exit code: 2

@collins It’s hard to know for certain, as you’ve only provided part of the log, and sometimes Netlify fails during Deployment, (but will show the fail as if it is against Building), usually when the folder you’re trying to deploy doesn’t exist.

It could also be because of this:

12:49:27 PM: <script src=dist/bundle.js> in /index.html can't be bundled without type=module attribute
transforming...

If you want that file to be bundled you need to have a type="module" attribute as per Vite’s Getting Started documentation.

The default behaviour on Netlify is that warnings are treated as errors and will cause your build to fail, so if that’s a warning it may be the cause.

You can disable that behaviour by setting CI to false, the easiest way to do that is to change your build command from npm run build to CI= npm run build

Hopefully it’s one of the usual “gotchas” above, but if you keep having trouble just provide a bit more detail.

1 Like