Angular-cli: ng build Module not found: Error: Recursion in resolving

Created on 25 Jun 2020  ·  9Comments  ·  Source: angular/angular-cli

🐞 Bug report

Command (mark with an x)

  • [ ] new
  • [x] build
  • [ ] serve
  • [ ] test
  • [ ] e2e
  • [ ] generate
  • [ ] add
  • [ ] update
  • [ ] lint
  • [ ] xi18n
  • [ ] run
  • [ ] config
  • [ ] help
  • [ ] version
  • [ ] doc

Is this a regression?

In Angular 9.x it the command was working fine

Description

Build broken in Angular 10.x

🔬 Minimal Reproduction

Project demo/angular here https://github.com/matteobruni/tsparticles/tree/dev/demo/angular, if you run yarn build:disabled you get the error (the script has :disabled for CI)

🔥 Exception or Error


0% compiling
Compiling @angular/core : es2015 as esm2015

Compiling @angular/common : es2015 as esm2015

Compiling @angular/platform-browser : es2015 as esm2015

Compiling @angular/platform-browser-dynamic : es2015 as esm2015

ERROR in ./src/app/app.module.ts
Module not found: Error: Recursion in resolving
Stack:
  resolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  newResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  parsedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles module
  describedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles module
  rawModule: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  module: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  resolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  newResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  parsedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  describedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  relative: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  describedRelative: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  rawFile: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  file: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  relative: (/Users/matteo/Projects/GitHub Projects/tsparticles/wrappers/angular/dist/ng-particles) 
  describedRelative: (/Users/matteo/Projects/GitHub Projects/tsparticles/wrappers/angular/dist/ng-particles) 
 @ ./src/app/app.module.ts 4:0-67 12:12-29 15:8-25 24:20-37
 @ ./src/main.ts
 @ multi ./src/main.ts
ERROR in ./src/app/app.component.ts
Module not found: Error: Recursion in resolving
Stack:
  resolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  newResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  parsedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles module
  describedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles module
  rawModule: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  module: (/Users/matteo/Projects/GitHub Projects/tsparticles/demo/angular/src/app) ng-particles/dist/ng-particles
  resolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  newResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  parsedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  describedResolve: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules) ./ng-particles/dist/ng-particles
  relative: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  describedRelative: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  rawFile: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  file: (/Users/matteo/Projects/GitHub Projects/tsparticles/node_modules/ng-particles/dist/ng-particles) 
  relative: (/Users/matteo/Projects/GitHub Projects/tsparticles/wrappers/angular/dist/ng-particles) 
  describedRelative: (/Users/matteo/Projects/GitHub Projects/tsparticles/wrappers/angular/dist/ng-particles) 
 @ ./src/app/app.component.ts 3:0-53 360:22-45
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi ./src/main.ts
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 10.0.0
Node: 12.17.0
OS: darwin x64

Angular: 10.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: 

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1000.0
@angular-devkit/build-angular      0.1000.0
@angular-devkit/build-ng-packagr   0.1000.0
@angular-devkit/build-optimizer    0.1000.0
@angular-devkit/build-webpack      0.1000.0
@angular-devkit/core               10.0.0
@angular-devkit/schematics         10.0.0
@ngtools/webpack                   10.0.0
@schematics/angular                10.0.0
@schematics/update                 0.1000.0
ng-packagr                         10.0.0
rxjs                               6.5.5
typescript                         3.9.5
webpack                            4.43.0

Anything else relevant?

devkibuild-angular browser medium regression bufix

Most helpful comment

Hit the same issue when upgrading to Version 10. I couldn't find the source of the change between 9 and 10 as the last commit seems to be merged already in 9 in the source BUT I can confirm that symlinks where the root of the issue.

The solution for me in the meantime is settting preserveSymlinks to true in angular.json under _architect->build/test->options_ but I don't know if there are specific sideeffects. Would be great if someone with more knowledge could leave an opinion on this.

EDIT: An alternative would be to execute ng build/test with the _--preserveSymlinks true_ argument as one would have to add the option to every relevant architect entry afaik.

All 9 comments

Hi @matteobruni,

I am unable to replicate the above error with the provided steps.

I encountered this following error

ERROR in src/app/app.module.ts:5:35 - error TS2307: Cannot find module 'ng-particles/dist/ng-particles' or its corresponding type declarations.

5 import { NgParticlesModule } from 'ng-particles/dist/ng-particles';

Which seems to be related to one of the imports.
https://github.com/matteobruni/tsparticles/blob/31cdc2ad3e54c70bf5710a1a250404e78f50b402/demo/angular/src/app/app.module.ts#L5

Which should be replaced with

import { NgParticlesModule } from 'ng-particles';

Hi @alan-agius4

Sorry I forgot some steps to be done in the root folder

yarn install && lerna bootstrap && lerna run build

This should build the library for the demo project. The path is correct with the list folder for a workaround with the lerna package management

EDIT: I don't know if the Angular wrapper has issues, the build completes without warnings. You can find it in wrappers/angular folder if you need more info

I get same issue updating from 9 to 10. Works fine in 9 fails in 10 with error

ERROR in ./src/app/app.module.ts
Module not found: Error: Recursion in resolving
...

Package causing problem is a local package referenced in package.json using file - https://docs.npmjs.com/files/package.json#local-paths

I'm getting the same issue after upgrading from 9 to 10 this morning. Was working like a champ with 9. Upgraded core, cli, and material, and now i'm getting blasted with these module recursion errors on app build. Library build with ng-packagr is working ok. But ng build on the app gives that for every module the app uses from the local library build.

Similar, i think, as @slubowsky. Thanks for jumping on this @alan-agius4

~This seems to be ts-lib related. When I include tsLib 1.13.0 as a dependency of my (CLI created) library) so I don't run into trouble with the tsLib 2.0.0 included in Angular v10, I get this error.
When I leave out the dependency, it compiles but fails during run-time. This seems to be a catch-22, an I hope we can find a solution for this.
Otherwise, I will have to separately build and maintain my libs for every major Angular version.~
My problem was caused by using a symlink in my node_modules. Fixed by not doing that.

Same here, problem caused by symlinking node_modules in my build process

Hit the same issue when upgrading to Version 10. I couldn't find the source of the change between 9 and 10 as the last commit seems to be merged already in 9 in the source BUT I can confirm that symlinks where the root of the issue.

The solution for me in the meantime is settting preserveSymlinks to true in angular.json under _architect->build/test->options_ but I don't know if there are specific sideeffects. Would be great if someone with more knowledge could leave an opinion on this.

EDIT: An alternative would be to execute ng build/test with the _--preserveSymlinks true_ argument as one would have to add the option to every relevant architect entry afaik.

Hit the same issue when upgrading to Version 10. I couldn't find the source of the change between 9 and 10 as the last commit seems to be merged already in 9 in the source BUT I can confirm that symlinks where the root of the issue.

The solution for me in the meantime is settting preserveSymlinks to true in angular.json under _architect->build->options_ but I don't know if there are specific sideeffects. Would be great if someone with more knowledge could leave an opinion on this.

Thanks, this is the workaround I was searching. My broken angular project is a demo one so I don't care about side effects for now.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings