[SalesForce] LightningComponentBundle “Not available for deploy for this API version” error

I receive a strange error "Not available for deploy for this API version" for deploying LightningComponentBundle by sfdx force:source:deploy command or by VS Code Menu Item "SFDX Deploy Source To Org".

21:55:35.494 sfdx force:source:deploy –sourcepath
d:\Reps\testname\salesforce\FLSMan\force-app\main\default\lwc\fls
–json –loglevel fatal {"message":"Deploy failed.","status":1,"stack":"DeployFailed: Deploy failed.\n at
ALMError (C:\Program Files\Salesforce
CLI\client\node_modules\salesforce-alm\dist\lib\almError.js:44:19)\n
at MetadataRegistry.initializeMetadataTypeInfos.then.catch.e
(C:\Program Files\Salesforce
CLI\client\node_modules\salesforce-alm\dist\lib\source\sourceApiCommand.js:67:35)\n
at tryCatcher (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\util.js:16:23)\n
at Promise._settlePromiseFromHandler (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\promise.js:510:31)\n
at Promise._settlePromise (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\promise.js:567:18)\n
at Promise._settlePromise0 (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\promise.js:612:10)\n
at Promise._settlePromises (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\promise.js:687:18)\n
at Async._drainQueue (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\async.js:138:16)\n
at Async._drainQueues (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\async.js:148:10)\n
at Immediate.Async.drainQueues (C:\Program Files\Salesforce
CLI\client\node_modules\bluebird\js\release\async.js:17:14)\n
at runCallback (timers.js:789:20)\n at tryOnImmediate
(timers.js:751:5)\n at processImmediate [as _immediateCallback]
(timers.js:722:5)","name":"DeployFailed","result":[{"error":"Not
available for deploy for this API
version","type":"LightningComponentBundle","filePath":"N/A"},{"error":"Not
available for deploy for this API
version","type":"LightningComponentBundle","filePath":"N/A"},{"error":"Not
available for deploy for this API
version","type":"LightningComponentBundle","filePath":"N/A"}],"warnings":["All
–json output, including on error, is moving to stdout. Use the SFDX_JSON_TO_STDOUT environment variable to move over to the new
functionality. This will become the default in version 45."]}
21:55:42.432 sfdx force:source:deploy –sourcepath
d:\Reps\testname\salesforce\IronMan\force-app\main\default\lwc\fls
–json –loglevel fatal ended with exit code 1

enter image description here

I use the newest version of VS Code and the newest version of Salesforce Extension Pack and I have updated Salesforce CLI and even reinstalled it but still receive the same error.

This is very confusing since when I convert the source to MDAPI format and deploy it with sfdx force:mdapi:deploy -d src command it works just fine!

Also definitely the org I am using is on version 45, since I was able to deploy LWC by mdapi:deploy command.

Best Answer

Looks like I have found already a culprit here. It is very important to check sourceApiVersion property of project.json configuration.

Looks like this value was 44.0 in my project. Probably because I have created it before updating the salesforce-cli tool. Then I updated the CLI and even reinstalled it but the project version has not been changed.

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    }
  ],
  "namespace": "",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": /*"44.0"=>*/"45.0"
}

Now after updating this configuration settings, it started working successfully.