-
Notifications
You must be signed in to change notification settings - Fork 156
o1js is not quite compatible with NodeNext TSC module resolution #1447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
oh that's bad! looking into it |
Btw, I don't get what exactly makes |
Another long-shot idea is that the cycle of imports between
|
Ok, I made a lot of progress debugging, will leave this draft PR here for now: #1448 The key change in that PR is to export With that PR, the following snippet type-checks. Note the many "unused" type imports, each of which is necessary to "name" the inferred type of import {
Bool,
Field,
ZkProgram,
Proof,
InternalBool,
InternalField,
Cache,
GateType,
Gate,
FieldVar,
FieldConst,
} from "o1js";
export { HelloProgram };
const HelloProgram = ZkProgram({
name: "hello-program",
publicInput: Field,
publicOutput: Bool,
methods: {
addition: {
privateInputs: [Field, Field],
method(sum: Field, a: Field, b: Field) {
return a.add(b).equals(sum);
},
},
},
}); alternatively, this could be used: import { Bool, Field, ZkProgram } from "o1js";
import type * as _o1js from "o1js"; // for type naming
export { HelloProgram };
const HelloProgram = ZkProgram({
name: "hello-program",
publicInput: Field,
publicOutput: Bool,
methods: {
addition: {
privateInputs: [Field, Field],
method(sum: Field, a: Field, b: Field) {
return a.add(b).equals(sum);
},
},
},
}); |
That's not ideal, but it works :) When is the release? |
not sure if we want to release that yet |
See also the discussion on discord https://discord.com/channels/484437221055922177/1205086733121888266 I've encountered many issues with o1js and nodenext in my MinaNFT library, and after trying many ways to resolve it, I finally decided to wait for TypeScript bug resolution microsoft/TypeScript#47663 and microsoft/TypeScript#48212. I believe that the bug is on TypeScript side, and only some temporary workarounds can be made in the o1js or minanft library. |
We should check if TypeScript 5.5 which includes microsoft/TypeScript#42873 resolves this |
@mitschabaude Nope. Does not work. Now even Updated the repro repo with the newest TS. |
I just struggled with this on a new repo again and was forced to use the deprecated module resolution mode there, vote for re-opening |
@mitschabaude According to the recent discussion on the TypeScript repo, this bug is fixed now in TypeScript, and if we see it, it is a problem with our imports that do not allow TypeScript to understand the type because of types not exported or that are not available due to the location of o1js. Making o1js being referenced as in this error message
cause errors, so in the case of monorepo, installing node_modules directly to the package resolves it. |
hm, I don't have a monorepo and get the "cannot be named" error all over the place when I switch to "nodenext" import resolution (I'm on the latest TS 5.7 beta) |
It is my configuration that works for me: I've also tried setting I believe that exporting some types from o1js that you use and ensuring that o1js path is acceptable for TypeScript can resolve the error. Also, o1js should be listed both in |
I have added a PR to your repo to convert it to NodeNext. Please check if it works for you. |
See also comment on zksecurity/mina-attestations#93 (comment) |
Given the comment above, maybe the problem is just that o1js uses Line 7 in dea2a1f
EDIT: no I tried removing it, doesn't seem to change anything |
Maybe something should be changed that will affect the "sourceRoot":"","sources":["../../../../src/lib/mina/account-update.ts"] Theoretically, exporting "./dist/node/index.js" and referencing the files above "./dist/node/index.js" should not create problems, but in practice maybe it can affect the paths |
Uh oh!
There was an error while loading. Please reload this page.
If you use
NodeNext
module resolution setting,an instance of
ZkProgram
can not be exported. TSC complains it can not actually infer types.See reproduction case: https://github.com/ukstv/o1js-nodenext-repro
Probably related issue: microsoft/TypeScript#47663
The text was updated successfully, but these errors were encountered: