A
arktypeβ€’4mo ago
PIat

Ark attest cannot find module error

Hello! In a pnpm monorepo, with @ark/attest installed in the workspace root and running pnpx run attest trace ., I get the following output:
...
Found & ignored ...
...
Starting: attest trace .
Debugger listening on ws://127.0.0.1:43611/c9521cad-1760-4b47-aa82-6525ed118c96
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/home/p/Documents/Projects/web/attest'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
...
Found & ignored ...
...
Starting: attest trace .
Debugger listening on ws://127.0.0.1:43611/c9521cad-1760-4b47-aa82-6525ed118c96
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/home/p/Documents/Projects/web/attest'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
What should I change to run it without issues?
103 Replies
ssalbdivad
ssalbdivadβ€’4mo ago
Well it looks like you're running from cjs so you'll need to add "type": "module" to your package.json It looks like from the stack trace attest's code is never executed
PIat
PIatOPβ€’4mo ago
Even with type module in the root package json it's giving the same error
ssalbdivad
ssalbdivadβ€’4mo ago
Try adding more context without all the ... I can't really see what's happening from that
PIat
PIatOPβ€’4mo ago
Are there any changes I need to make to the code itself? Maybe I didn't understand the docs?
ssalbdivad
ssalbdivadβ€’4mo ago
No haha You just install the package and run that command you can tell it is not even running attest's code Wait did you run pnpm attest trace? Or just attest trace npm installing something doesn't put it on your path Depending whether you're using npm/pnpm/yarn whatever just run it using that
PIat
PIatOPβ€’4mo ago
pnpm attest trace . and pnpx attest trace . throw the same error
ssalbdivad
ssalbdivadβ€’4mo ago
Show the whole output "Starting: attest trace ."
Starting: attest trace .
...
Error: Cannot find module '/home/p/Documents/Projects/web/attest'
This seems kinda sus
PIat
PIatOPβ€’4mo ago
> pnpx run attest trace .


Watching /home/p/Documents/Projects/web and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./.cache ; is listed in .gitignore
Found & ignored ./.turbo ; is listed in .gitignore

Starting: attest trace .
Debugger listening on ws://127.0.0.1:46625/06faf203-653b-4ac4-8960-6569e4784fce
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/home/p/Documents/Projects/web/attest'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
> pnpx run attest trace .


Watching /home/p/Documents/Projects/web and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./.cache ; is listed in .gitignore
Found & ignored ./.turbo ; is listed in .gitignore

Starting: attest trace .
Debugger listening on ws://127.0.0.1:46625/06faf203-653b-4ac4-8960-6569e4784fce
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1148
throw err;
^

Error: Cannot find module '/home/p/Documents/Projects/web/attest'
at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
at Module._load (node:internal/modules/cjs/loader:986:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
ssalbdivad
ssalbdivadβ€’4mo ago
That somehow it is not actually being resolved through node_modules
PIat
PIatOPβ€’4mo ago
Should I hoist it?
ssalbdivad
ssalbdivadβ€’4mo ago
No lol I mean I don't know what's going on but I don't just have some random fix this is not a normal issue it seems like something with your env Most attest users use pnpm like this So it doesn't just not work haha What isthe output for just pnpm attest trace .
PIat
PIatOPβ€’4mo ago
The help section +
Error: Command failed: pnpm tsc --noEmit --extendedDiagnostics --incremental false --tsBuildInfoFile null --generateTrace /home/p/Documents/Projects/web/.attest/trace
⏳ Analyzing type trace data for ....
Error: Command failed: pnpm tsc --noEmit --extendedDiagnostics --incremental false --tsBuildInfoFile null --generateTrace /home/p/Documents/Projects/web/.attest/trace
⏳ Analyzing type trace data for ....
ssalbdivad
ssalbdivadβ€’4mo ago
Just paste the whole thing Including the command and all output
PIat
PIatOPβ€’4mo ago
ssalbdivad
ssalbdivadβ€’4mo ago
okay maybe I just broke it with the release yesterday then because I just changed how ts aliases are loaded It worked for me locally but maybe something externally breaks
PIat
PIatOPβ€’4mo ago
Should I try an older version?
ssalbdivad
ssalbdivadβ€’4mo ago
You can try 0.17.0 As a test
PIat
PIatOPβ€’4mo ago
It's the same So an issue on my end
ssalbdivad
ssalbdivadβ€’4mo ago
Oh yeah it works for me haha
PIat
PIatOPβ€’4mo ago
I'll try messing around and see where the issue is
ssalbdivad
ssalbdivadβ€’4mo ago
To be fair I did screw up this logging though with the new aliases it should say Gathering type trace data for default or something
PIat
PIatOPβ€’4mo ago
Not really an issue :)
ssalbdivad
ssalbdivadβ€’4mo ago
It's really weird that this can even go wrong
No description
ssalbdivad
ssalbdivadβ€’4mo ago
What happens when you run this command directly: pnpm tsc --noEmit --extendedDiagnostics --incremental false --tsBuildInfoFile null --generateTrace .
PIat
PIatOPβ€’4mo ago
PIat
PIatOPβ€’4mo ago
It's just the help section
ssalbdivad
ssalbdivadβ€’4mo ago
Well you've lost me lol That's just a vanilla TS command it runs fine for me Don't know where else to go with that
PIat
PIatOPβ€’4mo ago
Should I be running it from the workspace root? I don't have a tsconfig file there per Turborepo's recommendation
ssalbdivad
ssalbdivadβ€’4mo ago
It shouldn't matter as long as wherever you run it from typescript is resolvable You're right that is what happens if you have no tsconfig You can try running it in a package dir with tsconfig That's such a bad error from TS though I don't get it
PIat
PIatOPβ€’4mo ago
It's doing something!
ssalbdivad
ssalbdivadβ€’4mo ago
They don't even mention anything about needing a config, they just output a help message if you don't have one? @Andarist would you expect that?
> node ./node_modules/typescript/lib/tsc.js "--noEmit" "--extendedDiagnostics" "--incremental" "false" "--tsBuildInfoFile" "null" "--generateTrace" "."

Version 5.6.2
tsc: The TypeScript Compiler - Version 5.6.2
TS
COMMON COMMANDS

tsc
Compiles the current project (tsconfig.json in the working directory.)
...
> node ./node_modules/typescript/lib/tsc.js "--noEmit" "--extendedDiagnostics" "--incremental" "false" "--tsBuildInfoFile" "null" "--generateTrace" "."

Version 5.6.2
tsc: The TypeScript Compiler - Version 5.6.2
TS
COMMON COMMANDS

tsc
Compiles the current project (tsconfig.json in the working directory.)
...
Andarist
Andaristβ€’4mo ago
Could u tldr for me?
ssalbdivad
ssalbdivadβ€’4mo ago
I run this command and if there is no tsconfig in the dir it just outputs --help Works fine if there is a tsconfig I guess that's what this is supposed to clarify:
tsc
Compiles the current project (tsconfig.json in the working directory.)

tsc app.ts util.ts
Ignoring tsconfig.json, compiles the specified files with default compiler options.
tsc
Compiles the current project (tsconfig.json in the working directory.)

tsc app.ts util.ts
Ignoring tsconfig.json, compiles the specified files with default compiler options.
Andarist
Andaristβ€’4mo ago
Is the result the same when u try to run tsc with no cli args?
ssalbdivad
ssalbdivadβ€’4mo ago
Yeah I have never really tried to run tsc with no config so I've never seen this haha
Andarist
Andaristβ€’4mo ago
Me neither ;p
ssalbdivad
ssalbdivadβ€’4mo ago
But it seems like such an unhelpful error message I would have known immediately what to do if it just said "Running tsc with no args requires a tsconfig.json file"
Andarist
Andaristβ€’4mo ago
PRs are welcome - as i say πŸ˜›
ssalbdivad
ssalbdivadβ€’4mo ago
Do they say why they recommend this? I can't imagine it would hurt to have one
ssalbdivad
ssalbdivadβ€’4mo ago
Yeah, I am just worried it will languish and not get feedback or get rejected haha but this one seems like a pretty straightforward win Hmmm, that is weird. It doesn't seem like it should matter if there is a root tsconfig as long as each package just extends it Although this is the monorepo setup I recommend (w/ --customConditions): https://colinhacks.com/essays/live-types-typescript-monorepo IMO just being able to run/infer .ts in dev >>> needing watch mode all the time And it's increasingly broadly viable now that --experimental-strip-types is built in to node I will add some custom error handling for no tsconfig here
PIat
PIatOPβ€’4mo ago
Thank you for helping me with this Is it normal do have 1882720 ids in the types.json?
ssalbdivad
ssalbdivadβ€’4mo ago
It is a big file yeah
PIat
PIatOPβ€’4mo ago
Is there something I should look into the most to understand where the bottlenecks are?
ssalbdivad
ssalbdivadβ€’4mo ago
No description
ssalbdivad
ssalbdivadβ€’4mo ago
Creates a trace.json file in .attest/trace that can be viewed as a type performance heat map via a tool like https://ui.perfetto.dev/. Also summarizes any hot spots as identified by @typescript/analyze-trace. Trace expects a single argument representing the root directory of the root package for which to gather type information.
PIat
PIatOPβ€’4mo ago
AHHHH Now I get it...
PIat
PIatOPβ€’4mo ago
So with such a trace
No description
PIat
PIatOPβ€’4mo ago
This is the worst offender?
No description
ssalbdivad
ssalbdivadβ€’4mo ago
the types.json file can be used to associate IDs from the trace file with type aliases 17s? That's fucking awful That has to be the worst I've seen for 1 type
PIat
PIatOPβ€’4mo ago
😬
ssalbdivad
ssalbdivadβ€’4mo ago
What is it lol
PIat
PIatOPβ€’4mo ago
Let's see
{"id":4660,"symbolName":"domainOf","recursionId":924,"aliasTypeArguments":[4644],"conditionalCheckType":9,"conditionalExtendsType":4644,"conditionalTrueType":-1,"conditionalFalseType":-1,"firstDeclaration":{"path":"/home/p/Documents/Projects/web/node_modules/.pnpm/@[email protected]/node_modules/@ark/util/out/domain.d.ts","start":{"line":21,"character":54},"end":{"line":22,"character":336}},"flags":["Conditional","IncludesEmptyObject"]},
{"id":4660,"symbolName":"domainOf","recursionId":924,"aliasTypeArguments":[4644],"conditionalCheckType":9,"conditionalExtendsType":4644,"conditionalTrueType":-1,"conditionalFalseType":-1,"firstDeclaration":{"path":"/home/p/Documents/Projects/web/node_modules/.pnpm/@[email protected]/node_modules/@ark/util/out/domain.d.ts","start":{"line":21,"character":54},"end":{"line":22,"character":336}},"flags":["Conditional","IncludesEmptyObject"]},
I guess this?
ssalbdivad
ssalbdivadβ€’4mo ago
Just what is in that position in the actual file?
PIat
PIatOPβ€’4mo ago
In the TS file?
ssalbdivad
ssalbdivadβ€’4mo ago
Yeah
PIat
PIatOPβ€’4mo ago
export type Primitive = inferDomain<PrimitiveDomain>;
export type domainOf<data> = unknown extends data ? Domain : data extends object ? "object" : data extends string ? "string" : data extends number ? "number" : data extends boolean ? "boolean" : data extends undefined ? "undefined" : data extends null ? "null" : data extends bigint ? "bigint" : data extends symbol ? "symbol" : never;
export type Primitive = inferDomain<PrimitiveDomain>;
export type domainOf<data> = unknown extends data ? Domain : data extends object ? "object" : data extends string ? "string" : data extends number ? "number" : data extends boolean ? "boolean" : data extends undefined ? "undefined" : data extends null ? "null" : data extends bigint ? "bigint" : data extends symbol ? "symbol" : never;
No description
PIat
PIatOPβ€’4mo ago
It's the domain.d.ts, is that right?
ssalbdivad
ssalbdivadβ€’4mo ago
Well there's a few questions haha
PIat
PIatOPβ€’4mo ago
I'm ready
ssalbdivad
ssalbdivadβ€’4mo ago
One would be you probably need to enable skipLibCheck in your tsconfig to avoid typechecking your deps But also that it is a very trivial type so there is no way that alone could be the source of something that takes 17 seconds
PIat
PIatOPβ€’4mo ago
Definitely not
PIat
PIatOPβ€’4mo ago
I have this in the tsconfig of the project I ran the attest command in
No description
PIat
PIatOPβ€’4mo ago
And every package extends a tsconfig with "skipLibCheck": true,
ssalbdivad
ssalbdivadβ€’4mo ago
Hmm I mean type instantiations can still occur even with skipLibCheck on but that would usually be how a dep contributes a lot
PIat
PIatOPβ€’4mo ago
I have this file
No description
ssalbdivad
ssalbdivadβ€’4mo ago
So that first huge source file that is checked is domain.d.ts?
PIat
PIatOPβ€’4mo ago
Yes I needed this because of the not portable error
ssalbdivad
ssalbdivadβ€’4mo ago
I don't know what the side effects of that are. I wouldn't guess they'd be that, but I would definitely try and avoid doing that if possible haha
PIat
PIatOPβ€’4mo ago
And this package takes about 15-20 seconds to build the DTS files Well they are real bad
ssalbdivad
ssalbdivadβ€’4mo ago
Maybe try reading this comment about where that error comes from and see if you can find another solution: https://x.com/ssalbdivad/status/1834752360729530575
David Blass (@ssalbdivad) on X
@mmkalmmkal @mattpocockuk Agree, would love to have some content on this that synthesizes @SeaRyanC's comment with other context on this issue. Definitely a fairly universal pain point among library/monorepo maintainers in the ecosystem. https://t.co/k0hvGB6s9I
Twitter
ssalbdivad
ssalbdivadβ€’4mo ago
GitHub
Check nearest package.json dependencies for possible package names ...
Implements this comment. I won&#39;t say this &quot;fixes&quot; #42873, but it does prevent it from occurring for people in workspaces with appropriately set-up explicit dependencies in...
PIat
PIatOPβ€’4mo ago
The things is, I was trying to make the package have an exported config which uses Arktype types and exports the object. And then this object is imported in all other packages with the inferred types
ssalbdivad
ssalbdivadβ€’4mo ago
Yeah it is true that transitive type resolutions like that can be tricky But can you just make ArkType a peer dependency?
PIat
PIatOPβ€’4mo ago
As in adding it to dependencies in package.json?
ssalbdivad
ssalbdivadβ€’4mo ago
peerDependencies should require that the other package also installs it Or rather that the other package installs it and you will use that version
PIat
PIatOPβ€’4mo ago
Woooow!!!!
ssalbdivad
ssalbdivadβ€’4mo ago
Then you can make it a devDependency locally
PIat
PIatOPβ€’4mo ago
I never heard about this
ssalbdivad
ssalbdivadβ€’4mo ago
You will, they cause a lot of problems TBH lol
PIat
PIatOPβ€’4mo ago
Only saw it in libraries I guess
ssalbdivad
ssalbdivadβ€’4mo ago
I mean it only makes sense as a library author to have them By definition you have to have people depending on your package for it to be meaningful
PIat
PIatOPβ€’4mo ago
No description
ssalbdivad
ssalbdivadβ€’4mo ago
Is that good?
PIat
PIatOPβ€’4mo ago
Not really
ssalbdivad
ssalbdivadβ€’4mo ago
Haha okay well you know 17 seconds on one type 8 seconds for the rest isn't bad πŸ˜›
PIat
PIatOPβ€’4mo ago
I don't know what to look for 😬
ssalbdivad
ssalbdivadβ€’4mo ago
I would probably try and start from an empty repo and see if you can bisect where these problems occur adding more of your code/configs
PIat
PIatOPβ€’4mo ago
I never build types. I only do it here for the not portable error
ssalbdivad
ssalbdivadβ€’4mo ago
It's tricky and takes a lot of practice TBH, that's how I make consulting money πŸ˜…
PIat
PIatOPβ€’4mo ago
Nice!
ssalbdivad
ssalbdivadβ€’4mo ago
What is the exact not portable error you get?
PIat
PIatOPβ€’4mo ago
None right now... But when I import a function with such a signature
export async function runJob<Q extends QueueName, J extends QueueJobName<Q>>(
queueName: Q,
jobName: J,
// @ts-ignore some indexation issues
data: UserJobInput[J],
// @ts-ignore same
): Promise<UserJobOutput[J]> {
export async function runJob<Q extends QueueName, J extends QueueJobName<Q>>(
queueName: Q,
jobName: J,
// @ts-ignore some indexation issues
data: UserJobInput[J],
// @ts-ignore same
): Promise<UserJobOutput[J]> {
It's imported as such
(alias) runJob<string, string>(queueName: string, jobName: string, data: UserJobInput): Promise<SubmitButton[string]>
import runJob
(alias) runJob<string, string>(queueName: string, jobName: string, data: UserJobInput): Promise<SubmitButton[string]>
import runJob
That's with this in package.json
"exports": {
"./*": {
"default": "./dist/*.js",
"types": "./src/*.ts"
}
}
"exports": {
"./*": {
"default": "./dist/*.js",
"types": "./src/*.ts"
}
}
With "types": "./dist/*.d.ts" there is no issue
(alias) runJob<"filter", "train">(queueName: "filter", jobName: "train", data: object): Promise<object>
import runJob
(alias) runJob<"filter", "train">(queueName: "filter", jobName: "train", data: object): Promise<object>
import runJob
So I guess there was an error with the dependency installation, as you've pointed out
ssalbdivad
ssalbdivadβ€’4mo ago
Where is this from?
"./*": {
"default": "./dist/*.js",
"types": "./src/*.ts"
}
"./*": {
"default": "./dist/*.js",
"types": "./src/*.ts"
}
You almost certainly don't want to be resolving types to a .ts file, that is definitely something that can screw up your build
PIat
PIatOPβ€’4mo ago
I was testing if the portable error would happen with that in place
ssalbdivad
ssalbdivadβ€’4mo ago
Did you read Ryan's comment? I would read that and try and come up with a new solution for what specifically you need to export for the type to be resolved
PIat
PIatOPβ€’4mo ago
The issue is gone after adding the package to peerDependencies, thank you
PIat
PIatOPβ€’4mo ago
Now running attest the biggest offender is this:
{"id":4609,"recursionId":2738,"intersectionTypes":[661,4608],"flags":["Intersection"]},

{"id":661,"symbolName":"forEach","recursionId":497,"firstDeclaration":{"path":"/home/p/Documents/Projects/web/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.es5.d.ts","start":{"line":1260,"character":104},"end":{"line":1266,"character":102}},"flags":["Object"],"display":"(callbackfn: (value: unknown, index: number, array: readonly unknown[]) => void, thisArg?: any) => void"},

{"id":4608,"symbolName":"forEach","recursionId":497,"firstDeclaration":{"path":"/home/p/Documents/Projects/btc/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.es5.d.ts","start":{"line":1260,"character":104},"end":{"line":1266,"character":102}},"flags":["Object"],"display":"(callbackfn: (value: unknown, index: number, array: readonly unknown[]) => void, thisArg?: any) => void"},
{"id":4609,"recursionId":2738,"intersectionTypes":[661,4608],"flags":["Intersection"]},

{"id":661,"symbolName":"forEach","recursionId":497,"firstDeclaration":{"path":"/home/p/Documents/Projects/web/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.es5.d.ts","start":{"line":1260,"character":104},"end":{"line":1266,"character":102}},"flags":["Object"],"display":"(callbackfn: (value: unknown, index: number, array: readonly unknown[]) => void, thisArg?: any) => void"},

{"id":4608,"symbolName":"forEach","recursionId":497,"firstDeclaration":{"path":"/home/p/Documents/Projects/btc/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/lib.es5.d.ts","start":{"line":1260,"character":104},"end":{"line":1266,"character":102}},"flags":["Object"],"display":"(callbackfn: (value: unknown, index: number, array: readonly unknown[]) => void, thisArg?: any) => void"},
No description
PIat
PIatOPβ€’4mo ago
No description
ssalbdivad
ssalbdivadβ€’4mo ago
Yeah that file is definitely not the issue haha... Tough to say without more investigation what is going on in your env, sadly I probably can't spent a lot more time speculating unless it is for a company that can pay me πŸ˜›
PIat
PIatOPβ€’4mo ago
What are your rates so that I can come back when possible? ☺️ You've already showed me so much, thank you πŸ™πŸ™πŸ™
ssalbdivad
ssalbdivadβ€’4mo ago
Usually I have people contact me individually for that, but if your company is genuinely considering it DM me!
Want results from more Discord servers?
Add your server