Sitecore / jss

Software development kit for JavaScript developers building web applications with Sitecore Experience Platform
https://jss.sitecore.com
Apache License 2.0
261 stars 275 forks source link

getMetadata() does not work when using npm workspaces #1812

Closed mg-aceik closed 2 weeks ago

mg-aceik commented 5 months ago

Describe the Bug

Writing component builder to /home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/apps/aceik-demo/src/temp/componentBuilder.ts
Error: ENOENT: no such file or directory, scandir 'node_modules'
    at Object.readdirSync (node:fs:1525:3)
    at getMetadata (/home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/node_modules/@sitecore-jss/sitecore-jss-dev-tools/dist/cjs/templating/metadata.js:15:31)
    at generateMetadata (/home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/apps/aceik-demo/scripts/generate-metadata.ts:13:41)
    at Object.<anonymous> (/home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/apps/aceik-demo/scripts/generate-metadata.ts:10:1)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module.m._compile (/home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Object.require.extensions.<computed> [as .ts] (/home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1019:12) {
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: 'node_modules'
}
npm error Lifecycle script `bootstrap` failed with error:
npm error Error: command failed
npm error   in workspace: @aceik-demo/aceik-demo@0.0.0
npm error   at location: /home/runner/work/aceik-sandpit-xmc/aceik-sandpit-xmc/src/rendering/apps/aceik-demo
Error: Process completed with exit code 1.

To Reproduce

  1. npx create-sitecore-jss nextjs,nextjs-sxa,nextjs-multisite,nextjs-xmcloud
  2. Configure the structure into an npm workspace per https://docs.npmjs.com/cli/v10/using-npm/workspaces then run npm install so that the node_modules folder doesn't exist in the same directory as the app, but is instead in a parent folder
  3. npm run build

Expected Behavior

Build success

Possible Fix

Update https://github.com/Sitecore/jss/blob/8c23ac3af2341d0115268349581891fd9d049ebd/packages/sitecore-jss-dev-tools/src/templating/metadata.ts to have better error handling

Provide environment information

Sitecore Version: XM Cloud JSS Version: 22.0.0 Browser Name and version: Chrome latest Operating System and version (desktop or mobile): Windows 11 Link to your project (if available): n/a

illiakovalenko commented 4 months ago

@mg-aceik Thank you for submitting this ticket! I've added a ticket containing all the details to our internal backlog for thorough review

yavorsk commented 2 weeks ago

Hey @mg-aceik! This issue has been fixed and should be part of our next release. thanks again for submitting :)