7

I have a library that I'm able to compile with Angular 9. But if I change the flag to --prod, which practically makes "enableIvy": false then I get

[error] RangeError: Maximum call stack size exceeded

at Object.pathIsRelative (...\node_modules\typescript\lib\typescript.js:5778:34)

at tryLoadModuleUsingPathsIfEligible (...\node_modules\typescript\lib\typescript.js:28346:37)

at tryLoadModuleUsingOptionalResolutionSettings (...\node_modules\typescript\lib\typescript.js:28334:24)

at tryResolve (...\node_modules\typescript\lib\typescript.js:28479:28)

at ...\node_modules\typescript\lib\typescript.js:28471:69

at Object.forEach (...\node_modules\typescript\lib\typescript.js:309:30)

at nodeModuleNameResolverWorker (...\node_modules\typescript\lib\typescript.js:28471:25)

at nodeModuleNameResolver (...\node_modules\typescript\lib\typescript.js:28464:16)

at Object.resolveModuleName (...\node_modules\typescript\lib\typescript.js:28238:30)

at CompilerHostAdapter.getMetadataFor (...\node_modules@angular\compiler-cli\src\metadata\bundler.js:567:37)

I introduced a console debug message in function tryLoadModuleUsingPathsIfEligible(extensions, moduleName, loader, state) function and it seems to be a loop with approximately 20 moduleNames. I have to mention that I do NOT have any circular dependency warning if I compile without --prod flag.

Update: I fixed the circular dependencies and I have no more warnings of sort.

Adrian Ber
  • 18,774
  • 9
  • 64
  • 106
  • try resolve circular dependency, (if it's about inject) this SO: https://stackoverflow.com/questions/46832072/how-to-solve-the-circular-dependency or this https://stackoverflow.com/questions/58749172/angular-circular-dependency-warning SO (it's about change modules) can be help you – Eliseo Jul 07 '20 at 07:19
  • @Eliseo I fixed the circular dependencies in my project, but I still get the same error. – Adrian Ber Jul 10 '20 at 11:56
  • @AdrianBer, have you managed to solve this issue? – Sobvan Nov 19 '20 at 19:35

4 Answers4

7

I had the same problem with angular 12.1.1, I had no circular dependenicies, the solutution was to change "enableIvy: false" to "compilationMode": "partial".

See angular docs.

Sh Svyatoslav
  • 316
  • 4
  • 11
  • 1
    That fixed my problem! Thanks! I upgraded a rather complex library to v12 and was searching for circular dependencies for ages. – Stefan R Oct 19 '21 at 06:27
  • setting enableIvy to true in angularCompilerOptions of the tsconfig I was using solved the issue for me – dmbarreiro Oct 27 '21 at 06:33
1

Try deleting unnecessary imports, if anything like this:

'A' module imports 'B' module and vice versa

Salahuddin Ahmed
  • 3,154
  • 3
  • 10
  • 33
0

In the end, aber rm -rf node_modules I also needed to do npm cache clean --force - also I made sure I really had all dependencies updated. (Not sure which of those things did the trick)

LuJaks
  • 851
  • 1
  • 9
  • 18
0

Been facing the same issue, in my case there was index.ts with invalid export

export * from './'

Fixed it and it build again with ng build

alydemah
  • 11
  • 1
  • 6