How do I create a scratch org that has the same namespace as my Developer Edition org where the managed package is held?

I've followed the instructions in the "Link a Namespace to a Dev Hub Org" page to link the namespace to my Dev Hub org, but I cannot find any instructions on any of the documentation pages below for how to actually create a new scratch org that has the same namespace as my DE org.

2 Answers 2


In the project configuration file, specify the namespace.

"packageDirectories" : [ 
    { "path": "force-app", "default": true}
"namespace": "myns", 
"sfdcLoginUrl" : "https://login.salesforce.com", 
"sourceApiVersion": "44.0"

This really only alluded to in the documentation, but sfdx-project.json is the key to creating a scratch org with a namespace.

  • 2
    Also worth noting that the namespace has to be registered in your dev org, otherwise you'll get a cryptic error message about some kind of standard javascript name, IIRC.
    – berry120
    Sep 28, 2018 at 20:38
  • 1
    Beautiful. Worked like a charm!
    – Marty C.
    Oct 1, 2018 at 15:50
  • 1
    Thanks for clarifying. I would totally expect the namespace setting to be in the scratch org definition file, and not the project file. So confusing. Jun 9, 2019 at 19:53
  • @sfdxfox- i need to create a scratch org without namespace. Would I then just make namespace field blank?
    – Seyitbek
    Oct 22, 2019 at 16:39
  • 1
    @Seyitbek yes, use the empty string ("") to denote that there is no namespace.
    – sfdcfox
    Oct 22, 2019 at 16:59

Link a Namespace to a Dev Hub

You should have two developer edition orgs :

  • Packaging org : that contains the managed packages and the namespace
  • Development org :that we use to create the scratch org


  1. Enable devhub in the development dev org

  2. [development dev org] Go to profile (system admin) make sure that "SalesforceDX Namespace Registry" is checked

  3. [development dev org] From the app launcher look for "Namespace Registries" list view

  4. [development dev org] Click on link namespace and authorize the Packaging org

  5. Add namespace attribute to the sfdx-project.json file:

"namespace": "your_name_space"

  1. Create the scratch org

    sfdx force:org:create -s -a -f config/project-scratch-def.json -d


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .