Skip to content
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

Failing to generate types for @account-abstraction/contracts #816

Open
naddison36 opened this issue Mar 15, 2023 · 2 comments
Open

Failing to generate types for @account-abstraction/contracts #816

naddison36 opened this issue Mar 15, 2023 · 2 comments

Comments

@naddison36
Copy link

I'm trying to use the ERC-4337 contracts in the @account-abstraction/contracts package.

I've created a simple Hardhat project that attempts to compile and generate types for the @account-abstraction contracts. To replicate, please use the typechain branch as that is barebones.
https://github.com/naddison36/abstract-accounts/tree/typechain

When I compile the project using yarn compile, I get the following error

Generating typings for: 17 artifacts in dir: src/types/typechain for target: ethers-v5
An unexpected error occurred:

SyntaxError: 'from' expected. (4:24)
  2 | /* tslint:disable */
  3 | /* eslint-disable */
> 4 | import type * as  from './..';
    |                        ^
  5 | export type {  };
  6 | export * as accountAbstraction from './@account-abstraction';
  7 | export * as openzeppelin from './@openzeppelin';
    at D (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/parser-typescript.js:1:17100)
    at LT (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/parser-typescript.js:257:10765)
    at Object.RT [as parse] (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/parser-typescript.js:257:11074)
    at Object.parse (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/index.js:7515:23)
    at coreFormat (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/index.js:8829:18)
    at formatWithCursor2 (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/index.js:9021:18)
    at /Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/index.js:38176:12
    at Object.format (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/prettier/index.js:38190:12)
    at prettierOutputTransformer (/Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/typechain/src/codegen/outputTransformers/prettier.ts:8:19)
    at /Users/nicholasaddison/Documents/workspaces/abstract-accounts/node_modules/typechain/src/typechain/io.ts:22:33 {
  loc: { start: { line: 4, column: 24 } },
  codeFrame: '\x1B[0m \x1B[90m 2 |\x1B[39m \x1B[90m/* tslint:disable */\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 3 |\x1B[39m \x1B[90m/* eslint-disable */\x1B[39m\x1B[0m\n' +
    "\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 4 |\x1B[39m \x1B[36mimport\x1B[39m type \x1B[33m*\x1B[39m \x1B[36mas\x1B[39m  \x1B[36mfrom\x1B[39m \x1B[32m'./..'\x1B[39m\x1B[33m;\x1B[39m\x1B[0m\n" +
    '\x1B[0m \x1B[90m   |\x1B[39m                        \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 5 |\x1B[39m \x1B[36mexport\x1B[39m type {  }\x1B[33m;\x1B[39m\x1B[0m\n' +
    "\x1B[0m \x1B[90m 6 |\x1B[39m \x1B[36mexport\x1B[39m \x1B[33m*\x1B[39m \x1B[36mas\x1B[39m accountAbstraction \x1B[36mfrom\x1B[39m \x1B[32m'./@account-abstraction'\x1B[39m\x1B[33m;\x1B[39m\x1B[0m\n" +
    "\x1B[0m \x1B[90m 7 |\x1B[39m \x1B[36mexport\x1B[39m \x1B[33m*\x1B[39m \x1B[36mas\x1B[39m openzeppelin \x1B[36mfrom\x1B[39m \x1B[32m'./@openzeppelin'\x1B[39m\x1B[33m;\x1B[39m\x1B[0m"
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Interestingly, types are created in the src/types and src/types/types folders. If I just use the Hardhat typechain plug-in defaults, types are created in typechain-types and the project root.

Screenshot 2023-03-15 at 10 54 28 am

I've kept the installed packages to a minimum to try and isolate the problem

npm ls
abstract-accounts@0.0.1 /Users/nicholasaddison/Documents/workspaces/abstract-accounts
├── @account-abstraction/contracts@0.5.0
├── @nomiclabs/hardhat-ethers@2.2.2
├── @openzeppelin/contracts@4.8.2
├── @typechain/ethers-v5@10.2.0
├── @typechain/hardhat@6.1.5
├── @types/node@18.15.3
├── defender-relay-client@1.39.0
├── ethers@5.7.2
├── hardhat@2.13.0
├── ts-generator@0.1.1
├── ts-node@10.9.1
├── typechain@8.1.1
└── typescript@4.9.5

The typechain config in Hardhat is

typechain: {
      outDir: "src/types/typechain",
      target: "ethers-v5",
  },
@andrevmatos
Copy link
Contributor

This seems to be caused by Typechain normalizing files/directories names by simply removing special symbols; in this case, it's importing from "./..", which after normalized, becomes "".
We got a similar issue, but with version-named folders:

import type * as 047 from './0.4.7';

047 is the naive normalization of the path, but isn't a valid identifier, and prettier is rightfully complaining.
Whatever function is generating those alias import names, should make sure they're both unique and valid.

@naddison36
Copy link
Author

Thanks for commenting @andrevmatos.

The contracts in @account-abstraction/contracts do use relative paths but so does openzeppelin-contracts which does work with Typechain when imported to a project.

Screenshot 2023-03-21 at 1 53 17 pm

I'll try stripping out the contracts in @account-abstraction/contracts to see if I can isolate which contracts are causing the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants