Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with "force:source:convert" command when using latest sfdx cli version #1106

Closed
allisonarnaud opened this issue Aug 5, 2021 · 33 comments
Labels
bug Issue or pull request that identifies or fixes a bug

Comments

@allisonarnaud
Copy link

Summary

Running command "force:source:convert" with latest version of sfdx cli ([email protected]) results in an error:
error

Steps To Reproduce:

  1. install latest sfdx cli version ([email protected]) via azure pipeline
  2. Run "force: source:convert" command

Expected result

Successful deployment

Actual result

Error with "force:source:convert" command failing

Additional information

The same process was used on monday without any issues, pointing towards a potential issue with sfdx version ([email protected]) released yesterday (04/08/21).

@allisonarnaud allisonarnaud added the investigating We're actively investigating this issue label Aug 5, 2021
@github-actions
Copy link

github-actions bot commented Aug 5, 2021

Thank you for filing this issue. We appreciate your feedback and will review the issue as soon as possible. Remember, however, that GitHub isn't a mechanism for receiving support under any agreement or SLA. If you require immediate assistance, contact Salesforce Customer Support.

@rasmuszimmer
Copy link

We are experiencing a similar issue after the latest update:

ERROR running force:source:convert: Component conversion failed: Cannot read property 'id' of undefined

@mshanemc
Copy link
Contributor

mshanemc commented Aug 5, 2021

@allisonarnaud @rasmuszimmer can you share some source in a repo that's failing to convert so we can find the bug?

the simplest source that'll reproduce the error is best. If not, any idea what metadata type is failing?

@lpbearden
Copy link

I'm also seeing this issue. When running I get: ERROR running force:source:convert: Cannot set property 'content' of undefined

And when running with the JSON flag I get:

{
  "status": 1,
  "name": "TypeError",
  "message": "Cannot set property 'content' of undefined",
  "exitCode": 1,
  "commandName": "Convert",
  "stack": "TypeError: Cannot set property 'content' of undefined\n    at DecomposedSourceAdapter.populate (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/adapters/decomposedSourceAdapter.js:77:35)\n    at DecomposedSourceAdapter.getComponent (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/adapters/baseSourceAdapter.js:47:21)\n    at MetadataResolver.resolveComponent (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:115:44)\n    at MetadataResolver.getComponentsFromPathRecursive (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:73:40)\n    at MetadataResolver.getComponentsFromPathRecursive (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:96:37)\n    at MetadataResolver.getComponentsFromPathRecursive (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:96:37)\n    at MetadataResolver.getComponentsFromPathRecursive (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:96:37)\n    at MetadataResolver.getComponentsFromPathRecursive (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:96:37)\n    at MetadataResolver.getComponentsFromPath (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/metadataResolver.js:43:25)\n    at Function.fromSource (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/collections/componentSet.js:67:46)\nOuter stack:\n    at Function.wrap (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/core/lib/sfdxError.js:171:27)\n    at Convert.catch (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/plugin-source/node_modules/@salesforce/command/lib/sfdxCommand.js:248:67)\n    at async Convert._run (/usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/plugin-source/node_modules/@salesforce/command/lib/sfdxCommand.js:85:13)\n    at async Config.runCommand (/usr/local/lib/node_modules/sfdx-cli/node_modules/@oclif/config/lib/config.js:173:24)\n    at async SfdxMain.run (/usr/local/lib/node_modules/sfdx-cli/node_modules/@oclif/command/lib/main.js:27:9)\n    at async SfdxMain._run (/usr/local/lib/node_modules/sfdx-cli/node_modules/@oclif/command/lib/command.js:43:20)\n    at async Object.run (/usr/local/lib/node_modules/sfdx-cli/dist/cli.js:162:47)",
  "warnings": []
}

@jayree
Copy link

jayree commented Aug 5, 2021

@allisonarnaud @lpbearden could you please check if you see this error if you convert your staticresources folder:
e.g. sfdx force:source:convert --sourcepath=force-app/main/default/staticresources/ --outputdir=anything

If yes, delete the folder staticresources, retrieve all staticresources from your org and try again.

@lpbearden
Copy link

@jayree I converted all of our staticresources without any issues.

@jayree
Copy link

jayree commented Aug 5, 2021

@lpbearden I had the same error because of some hidden files and folder e.g. __MACOSX in the staticresources folder. Perhaps you have files or folders like that somewhere else in your project?

@lpbearden
Copy link

I looked through the source being converted and found no hidden files, so I don't believe that is our issue.

@WillieRuemmele
Copy link
Member

Hi @lpbearden do you have a list of different metadata types you're trying to convert? I think there's a single type causing this bug

@shetzel
Copy link
Contributor

shetzel commented Aug 5, 2021

@lpbearden - can you open this file /usr/local/lib/node_modules/sfdx-cli/node_modules/@salesforce/source-deploy-retrieve/lib/src/resolve/adapters/decomposedSourceAdapter.js and just before line 77 where it does this: component.content = pathToContent; can you add console.dir(component); it should output what the component is that causes this.

@rasmuszimmer - can you append --dev-debug to the command and run it again. Then do something similar where you modify the source to console.dir the component that is causing the issue?

@lpbearden
Copy link

lpbearden commented Aug 5, 2021

@shetzel I ran the command and the output was quite large, so I just pulled out the names so here's my result of running sfdx force:source:convert --rootdir sfdxsrc/ --outputdir tmp_convert | grep "name:" Output is long so if you'd like me to post it in a gist instead let me know.

 name: 'Quick_Links__mdt',
    name: 'CustomObject',
  name: 'AccountContactRelation__x',
    name: 'CustomObject',
  name: 'Account__x',
    name: 'CustomObject',
  name: 'Agency_Company_Link__mdt',
    name: 'CustomObject',
  name: 'Agency_Contract_c__x',
    name: 'CustomObject',
  name: 'CI_YTD_Agency_Metrics_c__x',
    name: 'CustomObject',
  name: 'Call_Report_Attendees_External_c__x',
    name: 'CustomObject',
  name: 'Call_Report_Attendees_Internal_c__x',
    name: 'CustomObject',
  name: 'Call_Report_Distribution_List_c__x',
    name: 'CustomObject',
  name: 'Call_Report_c__x',
    name: 'CustomObject',
  name: 'CaseHistory__x',
    name: 'CustomObject',
  name: 'Case__x',
    name: 'CustomObject',
  name: 'Cases_Producer_Changes_c__x',
    name: 'CustomObject',
  name: 'Contact__x',
    name: 'CustomObject',
  name: 'GRM_Sub_Region_c__x',
    name: 'CustomObject',
  name: 'LeadHistory__x',
    name: 'CustomObject',
  name: 'Lead__x',
    name: 'CustomObject',
  name: 'Location_c__x',
    name: 'CustomObject',
  name: 'ProcessDefinition__x',
    name: 'CustomObject',
  name: 'ProcessInstanceHistory__x',
    name: 'CustomObject',
  name: 'ProcessInstanceNode__x',
    name: 'CustomObject',
  name: 'ProcessInstanceStep__x',
    name: 'CustomObject',
  name: 'ProcessInstanceWorkitem__x',
    name: 'CustomObject',
  name: 'ProcessInstance__x',
    name: 'CustomObject',
  name: 'ProcessNode__x',
    name: 'CustomObject',
  name: 'RecordType__x',
    name: 'CustomObject',
  name: 'Region_c__x',
    name: 'CustomObject',
  name: 'Related_Company_c__x',
    name: 'CustomObject',
  name: 'Territory_c__x',
    name: 'CustomObject',
  name: 'User__x',
    name: 'CustomObject',
  name: 'Account_Team_Assignment_Rule__c',
    name: 'CustomObject',
  name: 'BGI_Distribution_Underwriting__c',
    name: 'CustomObject',
  name: 'Case',
    name: 'CustomObject',
  name: 'Distribution_Territory__c',
    name: 'CustomObject',
  name: 'Objective__c',
    name: 'CustomObject',
  name: 'PE_Contact__e',
    name: 'CustomObject',
  name: 'PE_Deal_Close_Out__e',
    name: 'CustomObject',
  name: 'Prospect_Service_Account__c',
    name: 'CustomObject',
  name: 'Service_Account_Assignment__c',
    name: 'CustomObject',
  name: 'Service_Account__c',
    name: 'CustomObject',
  name: 'Service_Plan__c',
    name: 'CustomObject',
  name: 'UW_Segment__c',
    name: 'CustomObject',
  name: 'UW_Subsegment__c',
    name: 'CustomObject',
  name: 'Document__c',
    name: 'CustomObject',
  name: 'Endorsement__c',
    name: 'CustomObject',
  name: 'OCW_Genius_Policy_Program_Code__mdt',
    name: 'CustomObject',
  name: 'Submission_Document_Type_Assignment__mdt',
    name: 'CustomObject',
  name: 'Submission_Document_Type_Options__mdt',
    name: 'CustomObject',
  name: 'Task_Management_Information__mdt',
    name: 'CustomObject',
  name: 'OpportunityCustomDataCopy__mdt',
    name: 'CustomObject',
  name: 'BatchApexErrorLog__c',
    name: 'CustomObject',
  name: 'BatchApexError__c',
    name: 'CustomObject',
  name: 'Buyer_Product__c',
    name: 'CustomObject',
  name: 'Additional_Access_Mapping__mdt',
    name: 'CustomObject',
  name: 'App_Config__mdt',
    name: 'CustomObject',
  name: 'Generic_Detail_Page_Content__mdt',
    name: 'CustomObject',
  name: 'Generic_Detail_page__mdt',
    name: 'CustomObject',
  name: 'LOB_Mapping__mdt',
    name: 'CustomObject',
  name: 'NAS_MLOB_LOB_Mapping__mdt',
    name: 'CustomObject',
  name: 'NAS_Opportunity_Mapping__mdt',
    name: 'CustomObject',
  name: 'PS_to_Note_Category__mdt',
    name: 'CustomObject',
  name: 'SSI_URL__mdt',
    name: 'CustomObject',
  name: 'Segment_Product_Mapping__mdt',
    name: 'CustomObject',
  name: 'State_Code_Mapping__mdt',
    name: 'CustomObject',
  name: 'Tableau_URL__mdt',
    name: 'CustomObject',
  name: 'Account-en_US',
    name: 'CustomObjectTranslation',
  name: 'Activity-en_US',
    name: 'CustomObjectTranslation',
  name: 'Contact-en_US',
    name: 'CustomObjectTranslation',
  name: 'Opportunity-en_US',
    name: 'CustomObjectTranslation',
  name: 'A_B_Visit_Company__c',
    name: 'CustomObject',
  name: 'A_B_Visit_Detail__c',
    name: 'CustomObject',
  name: 'A_B_Visit_Email_Distribution__c',
    name: 'CustomObject',
  name: 'Account',
    name: 'CustomObject',
ERROR running force:source:convert:  Cannot set property 'content' of undefined

@shetzel
Copy link
Contributor

shetzel commented Aug 5, 2021

This would mean it's due to the Account object and I think it means that the code found a child of Account but not the Account component itself in the source. I believe this happens when you're adding fields to an existing standard object. Does this sound correct?

@lpbearden
Copy link

@shetzel That doesn't seem correct. We have the full Account object. The exact same metadata converts just fine in the previous versions of the CLI.

@shetzel
Copy link
Contributor

shetzel commented Aug 5, 2021

The previous versions of the CLI didn't use the source plugin and the SDR library though. So if you try to convert just the Account object it succeeds? To limit the output, can you wrap the console.dir you added with if (!component) so you only get the problem component.

@lpbearden
Copy link

Just the Account object results in:
ERROR running force:source:convert: Component conversion failed: Cannot read property 'id' of undefined

When adding in the if(!component) I just get

undefined
ERROR running force:source:convert:  Cannot set property 'content' of undefined

@WillieRuemmele
Copy link
Member

in the same location could you try adding

console.dir(trigger) // should be a sourcepath to the issue type
console.dir(metaXml.suffix) // should be the child suffix

thank you so much for your help

@lpbearden
Copy link

Here's the offending piece:
sfdxsrc/common/objects/AccountContactRelation/layouts/AccountContactRelation-Account Contact Relationship Layout.layout-meta.xml'

So its a layout, and looking at the metadata we don't have an AccountContactRelation.object-meta.xml file.

@shetzel
Copy link
Contributor

shetzel commented Aug 6, 2021

@lpbearden - that layout file is in the wrong location within the project. A layout file should be in a layouts directory peer to objects. Would you happen to know how it was written as a child of the object? It's possible that the old plugin code was accommodating for incorrect locations while the new plugin is not. If you move that file to the correct location (reset source tracking if you're using push/pull/status) and do the deploy again does it succeed? I think the code needs to throw if this condition happens and output the metadata details along with the expectations.

@lpbearden
Copy link

lpbearden commented Aug 6, 2021

@shetzel That's really interesting. All of our objects are laid out somewhat like this. Here's an example:

tree sfdxsrc/common/objects/Account -L 1
sfdxsrc/common/objects/Account
├── Account.object-meta.xml
├── classes
├── compactLayouts
├── duplicateRules
├── fieldSets
├── fields
├── layouts
├── listViews
├── matchingRules
├── recordTypes
├── validationRules
└── webLinks

I'm not really sure what led us to this layout originally, but a big reason we switched to Source format 3 years ago was flexibility in grouping and organizing our metadata. I'm assuming the SDR library you mentioned and this most recent version of the CLI have removed this unintended functionality.

@pfordey
Copy link

pfordey commented Aug 6, 2021

Having the same issue with 7.112.1. In our codebase we have a number of instances where we are adding fields, layouts etc... to a standard object or an object that is part of a managed package. We are not including those in our deployment as we are pushing to a 1st generation managed package. When we run force:source:convert to move from SFDX to Metadata format so it can be pushed to the packaging org into the correct namespace we get the following:

ERROR running force:source:convert: Metadata xml file /force-app/main/default/objects/hed__Term__c/hed__Term__c.object-meta.xml is forceignored but is required for/force-app/main/default/objects/hed__Term__c/fields/Add_Term_by_this_Date__c.field-meta.xml

Note that *** is a substitution of the full path I did to remove PII from the path.

If all the force ignore references to objects are removed we then get:

ERROR running force:source:convert: Component conversion failed: Cannot read property 'id' of undefined

Adding the debug code into the plug as shown above gives output that it is failing for an object

'***/force-app/main/default/objects/hed__Term__c/hed__Term__c.object-meta.xml'
'object'

All the source for that object holds is the meta file for the object itself and some fields.

If the functionality to be able to convert from source to metadata without having the object definition itself has been removed then we are in a difficult position as to be able to automatically add new metadata to a 1st gen package there is no method in source to do so unlike metadata format where you can specify the namespace to install into in the package.xml.

@shetzel
Copy link
Contributor

shetzel commented Aug 6, 2021

@pfordey - you are describing a different usecase that we definitely need to support. A field is a valid child of a CustomObject and the CustomObject meta file should not be required to deploy/retrieve. So my proposed solution of throwing if the parent is not found is incorrect. If you don't mind, could you open a new issue with this information along with the typical plugin versions, etc. Thanks!

@pfordey
Copy link

pfordey commented Aug 6, 2021

@shetzel #1110 has been created as requested

@shetzel
Copy link
Contributor

shetzel commented Aug 6, 2021

@lpbearden - please stand by. That metadata organization (specifically within the custom object dir) would not be as intended but it did happen to work just fine with 7.110.0 and previous versions. You are correct that the SDR (source-deploy-retrieve) library has different interpretation logic for metadata files and relies more on file system hierarchy for better performance and simpler, more maintainable code.

@shetzel shetzel added bug Issue or pull request that identifies or fixes a bug and removed investigating We're actively investigating this issue labels Aug 6, 2021
@uip-robot-zz
Copy link

This issue has been linked to a new work item: W-9720131

@shetzel
Copy link
Contributor

shetzel commented Aug 7, 2021

@lpbearden - We will fix the code to throw a better error message so that it's obvious which component caused the problem and what the solution is to fix it. However, nesting non-CustomObject children within a CustomObject folder was never an intended metadata organizational structure. There are still lots of benefits to source controlling your metadata in source format versus mdapi format, but the new source plugin will not support nested non-CustomObject children like that. I would use a pre 7.112 version of the CLI, restructure the metadata, then upgrade. Apologies for that inconvenience!

@lpbearden
Copy link

@shetzel the better error is good enough for me. Thanks for digging into this. Hope it wasn't too big of a rabbit hole for us just not following best practice!

@rasmuszimmer
Copy link

rasmuszimmer commented Aug 7, 2021

@shetzel sorry I was not able to contribute to the debugging sooner. The previous posts here led me to be able to narrow down to a few instances where some developer had carelessly placed metadata in incorrect folders.

First instance was a standard value set placed inside the object folder. When I corrected that I went from

"ERROR running force:source:convert: Component conversion failed: Cannot read property 'id' of undefined"
to "ERROR running force:source:convert: Component conversion failed: group.push is not a function"

after debugging and console.dir in that piece I was able to locate a customfieldtranslation that was put inside the main object translation xml instead of in its own file.

I can now convert the full source. Thanks for looking in to this!

Edit:
I was able to convert the source, but I am now facing a "gack" when actually deploying on our sandboxes... :((

@AndrewRayCode
Copy link

Same error on deploying, after a fresh install

sfdx --version
sfdx-cli/7.112.1 darwin-x64 node-v14.17.1
sfdx force:source:deploy -u Sandbox -x manifest/package.xml -w 60
*** Deploying with SOAP API ***
ERROR running force:source:deploy:  Cannot set property 'content' of undefined

Is there a workaround for this issue?

@AndrewRayCode
Copy link

AndrewRayCode commented Aug 9, 2021

Rolling back to previous version 7.110.0 does not seem to fix this issue

 sfdx plugins:install [email protected]
This plugin is not digitally signed and its authenticity cannot be verified. Continue installation y/n?: y
Finished digital signature check.
warning sfdx-cli > salesforce-alm > [email protected]: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
warning sfdx-cli > salesforce-alm > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning sfdx-cli > salesforce-alm > jsforce > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning sfdx-cli > salesforce-alm > @salesforce/source-deploy-retrieve > @salesforce/core > jsforce > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
warning sfdx-cli > salesforce-alm > request > [email protected]: this library is no longer supported
warning sfdx-cli > salesforce-alm > request > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning sfdx-cli > @salesforce/plugin-generator > nps-utils > opn-cli > temp-write > [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning sfdx-cli > @salesforce/plugin-generator > yeoman-environment > globby > fast-glob > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
warning sfdx-cli > @salesforce/plugin-generator > yeoman-environment > globby > fast-glob > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
warning "sfdx-cli > @salesforce/plugin-generator > [email protected]" has unmet peer dependency "eslint@>=7.20.0".
warning "sfdx-cli > @salesforce/plugin-generator > [email protected]" has unmet peer dependency "eslint@>=7.20.0".
warning "sfdx-cli > @salesforce/plugin-generator > eslint-config-xo-space > [email protected]" has unmet peer dependency "eslint@>=7.20.0".
Installing plugin sfdx-cli... installed v7.110.0

still produces:

$ sfdx force:source:deploy -u Sandbox -x manifest/package.xml -w 60
*** Deploying with SOAP API ***
ERROR running force:source:deploy:  Cannot set property 'content' of undefined

Same with sfdx plugins:install [email protected]

@rasmuszimmer
Copy link

@AndrewRayCode im not sure sfdx plugins:install [email protected] actually works and installs a previous version. Can you run sfdx version and confirm?

@allisonarnaud
Copy link
Author

I tried running the command locally with cli version 7.112.0 and was able to convert the data successfully, however trying to deploy the converted data fails with little information
image
I will raise a Salesforce Case to investigate further into the Org to get a better understanding of the failure.

@hariss63
Copy link

hariss63 commented Aug 13, 2021

We are getting the similar kind of issue recently

Version details,
sfdx-cli/7.113.0
win32-x64
node-v14.17.4

The error is,

Component conversion failed: Cannot read property 'contentType' of undefined

@shetzel
Copy link
Contributor

shetzel commented Aug 16, 2021

@hariss63 - that's a different error. Can you post a new issue with all the details in the template filled out please? We'll need the command and all flags used to produce the error, the stack trace for that error (append --dev-debug to the command and grab the stack trace towards the end or optionally --json flag should have it). It would also help us to provide a repository to reproduce the error or the problem metadata type if you discover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue or pull request that identifies or fixes a bug
Projects
None yet
Development

No branches or pull requests