if it's a script inside package.json you can try:
"build": "export NODE_OPTIONS=--openssl-legacy-provider; REST OF YOUR COMMAND"
or try to add a .npmrc file with
node-options=--openssl-legacy-provider