Skip to content

Nuxi fails to find Nuxt module when specifying the version #701

@schirrel

Description

@schirrel

Found when helping on the issue #697.

When trying to installing an specific version of a module, e.g. npx nuxi@latest module add content@2.13.0 an error is thrown:

ERROR Cannot read properties of undefined (reading 'dependencies')

I take a look at cli/packages/nuxi/src/commands/module/add.ts and even it have a regex validation and an assign of pkgName and pkgVersion:

  const reMatch = moduleName.match(packageRegex)
  if (reMatch) {
    if (reMatch[3]) {
      pkgName = `${reMatch[1] || ''}${reMatch[2] || ''}`
      pkgVersion = reMatch[3].slice(1)
    }
  }

when the command tries to find the match module on the modulesDB it keeps taking in consideration the initial moduleName, that contains the version:

  const matchedModule = modulesDB.find(
    module =>
      module.name === moduleName
      || module.npm === pkgName
      || module.aliases?.includes(pkgName),
  )

Yet it still possible to install a module with version if we describe the whole package name: npx nuxi@latest module add @nuxt/content@2.13.0 but it is kind of anoying when we have a Nuxt official module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions