Closed CoenWarmer closed 9 months ago
Hi @CoenWarmer my guess is the root cause is not that dependency-cruiser doesn't have exports or main fields in its package.json (it does). The error you see is one that occurs when attempting to require an ESM module from commonjs - and dependency-cruiser is ESM only. The snippet you show looks to be typescript, and a short peek at kibana's tsconfig base indeed shows the typescript compiler will emit commonjs (a.o. tsconfig.base.json#L1780 which explicitly sets that and tsconfig.base.json#L1794)
There's a few ways to work around that
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ESNext" // or "ES2022"
require
statements, defeating the purpose (unless you tsconfig it into emitting ESM). Amazing, thanks for your detailed help @sverweij! Going to try this, will report back.
Hey @sverweij, that was it. I'm still adapting the script to be used in the existing infra we have set up, but I at least have a working prototype. Thanks for your help!
Summary
Thank you for the great library!
I'm trying to get Dependency Cruiser to work on a large Typescript repository.
It has a tsconfig.json and .eslintrc.js file.
I'm calling it in a Node script like so:
When I run the script this is my output:
The package.json of this project has no
main
orexport
defined. I have tried runningdependency-cruiser --init
with different settings, and I've tried running it without.Any idea?
Context
I am trying to get a graph of all imports inside the repo, so I can request which file(s) are importing a specific file I am trying to test.
Environment