When changing XM Cloud build configuration for an environment in the xmcloud.build.json, note that startCommand has been deprecated and is ignored. You can use buildCommand and runCommand from the package.json file to run. However, deploying to XM Cloud might fail when using a custom env file with the "env-cmd" command at runCommand.
The following error can be found in logs:
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received undefined
To mitigate the issue, it is necessary to follow the correct format for specifying the path to the custom .env file like:
"build:custom": env-cmd -f <your env file path> <commands for env>
For example:
"build:custom": "env-cmd -f env/.env.production cross-env NODE_ENV=production npm-run-all --serial bootstrap next:build"
Sitecore recommends to test the above approach on the local development environment to ensure your scripts work properly, before using it on XM Cloud.