Shopify / cli

Build apps, themes, and hydrogen storefronts for Shopify
https://shopify.dev
MIT License
427 stars 130 forks source link

[Bug]: `shopify app dev` with `--config` argument asks which Partner Organization / App to connect to #3618

Closed vfonic closed 7 months ago

vfonic commented 7 months ago

Please confirm that you have:

In which of these areas are you experiencing a problem?

App, Extension

Expected behavior

yarn shopify app dev --config=my-config --tunnel-url=https://example.com:443 --no-update

Should pick up the Partner / App config from shopify.app.my-config.toml

Actual behavior

Fix a schema error in shopify.app.my-config.toml

Verbose output

> yarn shopify app dev --config=my-config --tunnel-url=https://example.com:443 --no-update
yarn run v1.22.21
$ shopify app dev --config=my-config --tunnel-url=https://example.com:443 --no-update
?  Which organization is this work for?
>  My Organization Name Here

Before proceeding, your project needs to be associated with an app.

?  Create this project as a new app on Shopify?
>   (n) No, connect it to an existing app

?  Which existing app is this for?   Type to search...
✔  My app name (shopify.app.my-config.toml)
╭─ error ─────────────────────────────────────────────────╮
│                                                         │
│  Fix a schema error in shopify.app.my-config.toml:      │
│  [                                                      │
│    {                                                    │
│      "code": "invalid_type",                            │
│      "expected": "string",                              │
│      "received": "undefined",                           │
│      "path": [                                          │
│        "name"                                           │
│      ],                                                 │
│      "message": "Required"                              │
│    },                                                   │
│    {                                                    │
│      "code": "invalid_type",                            │
│      "expected": "object",                              │
│      "received": "undefined",                           │
│      "path": [                                          │
│        "auth"                                           │
│      ],                                                 │
│      "message": "Required"                              │
│    },                                                   │
│    {                                                    │
│      "code": "invalid_type",                            │
│      "expected": "object",                              │
│      "received": "undefined",                           │
│      "path": [                                          │
│        "webhooks"                                       │
│      ],                                                 │
│      "message": "Required"                              │
│    },                                                   │
│    {                                                    │
│      "code": "invalid_type",                            │
│      "expected": "string",                              │
│      "received": "undefined",                           │
│      "path": [                                          │
│        "application_url"                                │
│      ],                                                 │
│      "message": "Required"                              │
│    },                                                   │
│    {                                                    │
│      "code": "invalid_type",                            │
│      "expected": "boolean",                             │
│      "received": "undefined",                           │
│      "path": [                                          │
│        "embedded"                                       │
│      ],                                                 │
│      "message": "Required"                              │
│    }                                                    │
│  ]                                                      │
│                                                         │
╰─────────────────────────────────────────────────────────╯

This was an error in 3.57.1. In 3.57.1 the app toml file would be pretty much completely "cleared". The only thing that remained was client_id. All the other, already existing settings, generated (download) by Shopify CLI, would be removed.

In 3.58.0, the toml file was left intact with all the settings. However, I get the following error now:

╭─ error ──────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                          │
│  Cannot read properties of null (reading 'appModuleVersions')                                            │
│                                                                                                          │
│  To investigate the issue, examine this stack trace:                                                     │
│    at activeAppVersion (@shopify/app/src/cli/utilities/developer-platform-client/partners-client.ts:308) │
│      appModuleVersions: version.appModuleVersions.map((mod) => {                                         │
│    at async fetchAppRemoteConfiguration (@shopify/app/src/cli/services/app/select-app.ts:30)             │
│      const activeAppVersion = await developerPlatformClient.activeAppVersion(remoteApp)                  │
│    at async link (@shopify/app/src/cli/services/app/config/link.ts:50)                                   │
│      const remoteAppConfiguration = await fetchAppRemoteConfiguration(                                   │
│    at async getAppContext (@shopify/app/src/cli/services/context.ts:789)                                 │
│      await link({directory, baseConfigName: previousCachedInfo?.configFile}, false)                      │
│    at async ensureDevContext (@shopify/app/src/cli/services/context.ts:162)                              │
│      const {configuration, cachedInfo, remoteApp} = await getAppContext({                                │
│    at async prepareForDev (@shopify/app/src/cli/services/dev.ts:87)                                      │
│      } = await ensureDevContext(commandOptions, developerPlatformClient)                                 │
│    at async dev (@shopify/app/src/cli/services/dev.ts:63)                                                │
│      const config = await prepareForDev(commandOptions)                                                  │
│    at run (@shopify/app/src/cli/commands/app/dev.ts:180)                                                 │
│      await dev(devOptions)                                                                               │
│                                                                                                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Reproduction steps

  1. Setup an app with config file with specific name, non default shopify.app.toml, but maybe shopify.app.my-config.toml
  2. yarn run shopify app dev --reset
  3. yarn shopify app dev --config=my-config --tunnel-url=https://example.com:443 --no-update

Operating System

macOS

Shopify CLI version (check your project's package.json if you're not sure)

3.58.0

Shell

zsh

Node version (run node -v if you're not sure)

v18 and v20

What language and version are you using in your application?

Ruby 3.2.2

vfonic commented 7 months ago

Everything was working fine on v3.57.1 when I was passing in the --config option. Then I noticed that, if I omit --config option, the wrong app (config) was being used.

So I did --reset and that messed everything up...

Please, would it be possible to do less magic and give more access to developers? Why is the default app/organization not stored somewhere visibly within the project? I can see only downsides of not having this publicly exposed to developers.

vfonic commented 7 months ago

I just tried yarn shopify auth logout, still getting the same error after logging back in...

EDIT: The same error when I try to create a new app.

│ Cannot read properties of null (reading 'appModuleVersions') │ ...

FYI new app got created. The error happens after the app is created.

vfonic commented 7 months ago

Here's the output from: https://github.com/Shopify/cli/blob/cec308092260996c1e16cf99d5aa97794018c05a/packages/app/src/cli/utilities/developer-platform-client/partners-client.ts#L307-L320

console.log(JSON.stringify(result, null, 2));
{
  "app": {
    "activeAppVersion": null
  }
}
vfonic commented 7 months ago

I managed to bypass this issue with:

async activeAppVersion({ apiKey }) {
    const variables = { apiKey };
    const result = await this.request(ActiveAppVersionQuery, variables);
    const version = result.app.activeAppVersion;
+    console.log(JSON.stringify(result, null, 2));
+
+    if (!version) return null
+
    return {
      ...version,
      appModuleVersions: version.appModuleVersions.map((mod) => {
        return {
          ...mod,
          config: mod.config ? JSON.parse(mod.config) : {},
        };
      }),
    };
  }
abhinavkumar940 commented 7 months ago

Having the same issue but somehow @vfonic's suggestion is also not fixing it for me. The error is gone but it keeps wiping my config file.

I am currently at:

"@shopify/app": "3.58.0",
"@shopify/cli": ""3.58.0"
amcaplan commented 7 months ago

Thanks to everyone for reporting this and providing details + investigations! This will help a lot in finding a resolution ASAP.

amcaplan commented 7 months ago

3.58.1 is out, and should solve this problem! I'm closing this issue, as I believe it's solved, but please do let us know if you continue to experience any trouble.