jss icon indicating copy to clipboard operation
jss copied to clipboard

getMetadata() is empty when using npm workspaces

Open jbluemink opened this issue 10 months ago • 1 comments

Describe the Bug

The fix for https://github.com/Sitecore/jss/issues/1812 is not working, when the Sitecore packages are coming from an monorepo.

In a Next.js project using a Turbo monorepo setup, Sitecore's Node module "sitecore-jss-dev-tools" function getMetadata() executes the following command:

npm query [name*=@sitecore] --workspaces false

However, this command fails to return any results when the dependencies are installed in a monorepo structure. Specifically, when running this command inside an app (apps/web), the Sitecore packages located in ./node_modules at the monorepo root are not detected. workspaces should be true, not false for this situation.

To Reproduce

Steps to Reproduce: Set up a Turbo monorepo with the following structure:

- apps/
    - web/
    - web2/
- node_modules/ (installed at monorepo root)
- packages

Define workspaces in package.json at the monorepo root:

{
  "private": true,
  "workspaces": [
    "apps/*",
    "packages/*"
  ]
}

The apps web, web2 has the jss modules as dependencies in the package.json: "dependencies": { "@sitecore-cloudsdk/events": "^0.4.0", "@sitecore-cloudsdk/core": "^0.4.0", "@sitecore-feaas/clientside": "^0.5.17", "@sitecore-jss/sitecore-jss-nextjs": "~22.4.1", "@sitecore/components": "^2.0.0", }

Run npm install from the monorepo root. Inside apps/web, execute:

npm query [name*=@sitecore] --workspaces false Observe that the result is empty, even though @sitecore packages exist in the monorepo and are used by app note: without --workspaces false it works, or when running from the monrepo root,

Start up the app and check if the temp/metadata.json is empty.

Expected Behavior

The metadata.json should be generated correct.

Possible Fix

An option to (config) run the command with--workspaces true, or running from the monrepo root should fix this.

Provide environment information

  • JSS Version: 22.4.1

jbluemink avatar Feb 07 '25 16:02 jbluemink

Thanks for the detailed submission, I am adding a ticket in our inbox to work on fixing this!

yavorsk avatar Feb 11 '25 11:02 yavorsk