-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Build fails with latest Angular #3910
Comments
It seems issue is more serious than I thought. Adding a skipLibCheck fixes the error but after that app does not work as expected, any attempt to communicate with Metamask wallet using BrowserProvider fails with an error like this:
You can use following repo to regenerate the issue: |
It doesn't look like ethers is in your package-lock.json? |
I also generally do not install an execute repos on my machine. Could you possibly include minimal reproduction steps using standard (well-known) CLI steps? |
Sure, here are the steps:
& ethers is not in package lock because I installed it using yarn, forgot to add package-lock in .gitignore. |
Can we just remove code of this line? |
I think your link is missing the filename? |
I'm sorry. link is https://github.com/ethers-io/ethers.js/blob/main/types/providers/provider-ipcsocket.d.ts#L1 |
Weird. I’m not even sure why it injects that line. The other |
because this module use lib "net" which is belong node lib |
I can reproduce it and have been looking at it for a few hours now. It looks like the asyncToGenerator is dereferencing the method, so it is no longer bound to the object. Still looking into it, just keeping you in the loop. Let me know if you figure anything out too. :) |
(oh, and I didn't need to add skipLibCheck; the only changes I made to the default package was changing the tsconfig |
FYI; seems related to this issue. |
I think I've found the code in ethers that is causing issues. If so, it is definitely a compiler bug in Angular which could be addressed by updating the version of Babel (I think). Here is the code in ethers which is totally valid, but it uses I'm a bit apprehensive about this change, since I'm sure there are plenty of places I use this pattern (as it is valid and really the entire reason for arrow functions). Is it easy to update the babel compiler within Angular? I'm still investigating, but this is what I've found so far. |
Ok but is this solution requires changing resolution to node16 or nodenext if yes angular might not fix quickly as by default they use module resolution node, but still I can create an issue with Angular. |
Oh, the Those are separate from the When I looked at the I don't really understand how this isn't a larger problem for them; surely ethers can't be the only library that uses arrow functions inside a method? :p |
If you are talking about this babel issue , then it seems it was fixed & angular is using newer version than required, these are the currently resolved versions: |
That version is still 3 months old, but it is likely fine. But if you look through the entire lock file, there are some places that specify a 5 year old (!!) version of babel. I'm not sure which dependency it pulls Tomorrow I will make a few small changes locally to verify that is the problem and will also create a smaller proof-of-concept to demonstrate if it is the problem. I don't know Angular, so I'm just reading through their code as best I can. |
FYI: I just tried it with next angular version (v16) which uses latest babel (7.21.3), & it still gives same (_getOption) error. I am attaching its package lock file for reference. |
Thanks. I’ll try more things out tomorrow. |
If we set |
Hi @marshalys yes but It is less serious issue, & can be fixed by adding & currently in NextJS too if I set But currently the main issue is it is not working in Angular even with |
Weird, I didn't get the error. It look fine.
|
Ok that's surprising do you see Network after you click Connect button? |
@marshalys yes it should display network after you allow wallet access, but it gives error, request accounts is called directly on ethereum object ethers is not used for this. |
Hi @ricmoo I have tried to narrow down the issue & found that it is related to some babel transform issue based on browser target if I target class Working {
_detectNetwork() {
var e = this;
return m(function* () {
const n = e._getOption("staticNetwork");
if (n) return n;
if (e.ready) return Kt.from(R(yield e.send("eth_chainId", [])));
const r = {
id: e.#t++,
method: "eth_chainId",
params: [],
jsonrpc: "2.0",
};
let s;
e.emit("debug", {
action: "sendRpcPayload",
payload: r,
});
try {
s = (yield e._send(r))[0];
} catch (i) {
throw (
(e.emit("debug", {
action: "receiveRpcError",
error: i,
}),
i)
);
}
if (
(e.emit("debug", {
action: "receiveRpcResult",
result: s,
}),
"result" in s)
)
return Kt.from(R(s.result));
throw e.getRpcError(r, s);
})();
}
}
class NonWorking {
_detectNetwork() {
return w(function* () {
var e,
n,
r = this;
const i = r._getOption("staticNetwork");
if (i) return i;
if (r.ready) return sn.from(B(yield r.send("eth_chainId", [])));
const s = {
id: (y(r, ao, ((e = p(r, ao)), (n = e++), e)), n),
method: "eth_chainId",
params: [],
jsonrpc: "2.0",
};
let o;
r.emit("debug", {
action: "sendRpcPayload",
payload: s,
});
try {
o = (yield r._send(s))[0];
} catch (a) {
throw (
(r.emit("debug", {
action: "receiveRpcError",
error: a,
}),
a)
);
}
if (
(r.emit("debug", {
action: "receiveRpcResult",
result: o,
}),
"result" in o)
)
return sn.from(B(o.result));
throw r.getRpcError(s, o);
})();
}
} In non working class this & var e, n & r will be undefined. If you can find the root cause then it would be possible to file an issue with Babel. & for now I have fixed it by targeting only latest browsers & adding skipLibCheck false. (because we are only using ethers only for admin app so can target only newer browsers) |
Same with |
FYI, there is now an Angular environment CI test, thanks to your work. So, the CI will fail if there are any future issues building an Angular app. See: https://github.com/ethers-io/ethers.js/blob/main/.github/workflows/test-env.yml#L56 Thanks! :) |
I believe this is now working, so I’ll close it again. Please re-open if it is still an issue. |
Hi @ricmoo only build error issue is fixed which was minor (can also be fixed by adding skipLibCheck in tsconfig), but actual error due to incorrect babel transform is still present (TypeError: Cannot read properties of undefined (reading '_getOption')). You can trust this repo, or you can also create new project using & see my previous comment for details (which has Working & NonWorking sample babel output for _detectNetwork function) |
Just checked with new builder & surprisingly it worked (esbuild based builder - which is currently in developer preview), |
But unfortunately this builder is not yet released for productive use. For instance, it does not yet support the internationalization (i18n) feature of Angular. |
If you have to use webpack based builder due to some custom config, you can try by targeting only latest browsers by adding browserslist or you can also try rspack based builder (unofficial), they are actively working on Angular support. & this is issue is related to babel but to create an issue with babel someone needs to narrow down further. as we have switched to new esbuild based builder I am not looking into now. |
Ethers Version
6.1.0
Search Terms
angular
Describe the Problem
Typescript shows this error when compiling:
moduleResolution node16 or nodenext are not working with official angular setup & node is currently a default for new angular project.
& due to this error build command is failing.
& as a workaround I have added
"skipLibCheck": true
in tsconfig.Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
node.js (v12 or newer)
Environment (Other)
Angular CLI
The text was updated successfully, but these errors were encountered: