Ng new my-layer0-spartacus-app npm errors

Following Layer0 Documentation - Spartacus Guide

ng new my-layer0-spartacus-app3 errors as follows:

⠸ Installing packages...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-layer0-spartacus-app4@0.0.0
npm ERR! Found: jasmine-core@3.5.0
npm ERR! node_modules/jasmine-core
npm ERR!   dev jasmine-core@"~3.5.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.7.1" from karma-jasmine-html-reporter@1.6.0
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR!   dev karma-jasmine-html-reporter@"^1.4.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/howard.ross/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/howard.ross/.npm/_logs/2021-05-19T20_43_23_643Z-debug.log
✖ Package install failed, see above.
The Schematic workflow failed. See above.

ng new my-layer0-spartacus-app4 --force
ng new my-layer0-spartacus-app4 --legacy-peer-dep
resolves the issue

I tried the steps in the docs with both Angular CLI 9 and 10 on Node 14 and did not receive those errors. It does fail with Node 16 though so I would check your active version. Both Layer0 and Angular CLI require Node 14.

Also the --force and --legacy-peer-deps flags are for npm and won’t have any effect when used with the ng command.

It appears that the dependencies in the package.json of @layer0/spartacus are sort of jumbled. It requires the same dependencies multiple times with different semvers:

  • @layer0/core”: “^3.10.0” in dependencies
  • @layer0/core”: “^3.0.0” in devDependencies
  • @layer0/core”: “^3.0.0” in peerDependencies

If @layer0/core contains a dependency tree wherein the required semver for a specific package is differs between the versions resolved from ^3.0.0 and ^3.10.0, the final dependency tree will have a dependency conflict. Additionally, there appear to be some dependencies that are used but not declared as dependencies.

@howie.ross What does eresolve-report.txt say? It should look like a big tree of dependency resolution steps. It shouldn’t contain any sensitive information but it wouldn’t hurt to check before posting it.

EDIT: See my comment below.

npm 7.x installs peer dependencies by default. If you didn’t receive the error under Node.js 14, your npm might actually be out of date. npm 7.x supports Node.js v10 onward which means those versions will also get the error if they keep their dependencies up-to-date.

You can verify this behavior by running the following commands:

Node.js 14 (returns an error)

$ npx -p npm@7 npm install

Node.js 16

$ npx -p npm@6 npm install

EDIT: This is an issue with Angular for the above reasons. There are conflicts among the dependencies installed by @angular/cli.

This is logged as XDN-11819