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

Cannot refer to node_modules in monorepo #411

Closed
2 tasks done
wshino opened this issue Jun 4, 2024 · 9 comments
Closed
2 tasks done

Cannot refer to node_modules in monorepo #411

wshino opened this issue Jun 4, 2024 · 9 comments
Labels

Comments

@wshino
Copy link

wshino commented Jun 4, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.0.2 (d94bab2 2024-06-04T00:25:36.901896000Z)

What command(s) is the bug in?

forge build --zksync

Operating System

macOS (Apple Silicon)

Describe the bug

It seems that current foundy-zksync cannot resolve some files in monorepo's node_modules dir in forge build --zksync.

Error (6275): Source "../node_modules/forge-std/src/Base.sol" not found: File outside of allowed directories. The following are allowed: ".".
ParserError: Source "../node_modules/forge-std/src/Base.sol" not found: File outside of allowed directories. The following are allowed: ".".
  --> ../node_modules/forge-std/src/Test.sol:27:1:
   |
27 | import {TestBase} from "./Base.sol";

I have foundry.toml properly configured with lib and fs_permissions. I did not encounter this error before; adding allow_paths did not help. Perhaps these settings are not crossing over to foundy-zksync properly? Is there a way to resolve this?
The build succeeds properly in forge build command (normal foundry).

I created an example repo created by forge init
If you do forge build --zksync in the contracts dir here, you should be able to reproduce the above problem.
https://github.com/wshino/foundry-zksync-example

Thank you.

@wshino wshino added the T-bug label Jun 4, 2024
@wshino wshino changed the title monorepoのnode_moduleが参照できない Cannot refer to node_module in monorepo Jun 4, 2024
@wshino wshino changed the title Cannot refer to node_module in monorepo Cannot refer to node_modules in monorepo Jun 4, 2024
@elfedy
Copy link
Contributor

elfedy commented Jun 24, 2024

There seem to be two issues here:

@koloz193
Copy link

ok so i tested it and with your setup it does in fact fail. if you move the contents of contracts one level up and add the deps to that higher level package.json it should work. The other option could be to install deps with forge install vs yarn

@Jrigada
Copy link
Contributor

Jrigada commented Aug 29, 2024

Hello @wshino. We merged recently a fix to be able to pass the allow_paths correctly to ZkSync context so the issue should be resolved. I tested the functionality with your repo and we created a test for this special case. Feel free to try it out and reach out to us if anything else comes up.

@Jrigada Jrigada closed this as completed Aug 29, 2024
@wshino
Copy link
Author

wshino commented Aug 29, 2024

@Jrigada Thank you so much! I've just tested the behavior on foundry-zksync-example. But forge build --zksync is still failing. I already installed foundry zksync which commit is c8e23ef319b58008adba8fe947e1717caca64ed7 is that correct?
Is there any configuration to be added?

@Jrigada
Copy link
Contributor

Jrigada commented Aug 29, 2024

Is the error you are getting still the same as before? In particular

Error (6275)
ParserError: Source "../node_modules/forge-std/src/safeconsole.sol" not found: File outside of allowed directories. The following are allowed: ".".

@Jrigada Jrigada reopened this Aug 29, 2024
@wshino
Copy link
Author

wshino commented Aug 29, 2024

Yes, somehow it's still happening. I'll send you more details if you want.

@Jrigada
Copy link
Contributor

Jrigada commented Aug 30, 2024

Yes no problem. I am not able to reproduce it even though I reset my environment. Do you have any other change in your repo? With the latest commit on main of foundry zksync it should work.

@koloz193
Copy link

koloz193 commented Sep 4, 2024

I was able to recreate the issue and figure out a workaround. Essentially you'll need to create a symlink within contracts to the parent folder's node_modules with ln -s node_modules contracts/node_modules and then update the foundry.toml to look like

[profile.default]
src = "src"
out = "out"
libs = ["node_modules", "lib"]
allow_paths = ["zkout"]

solc = "0.8.23"
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

and remappings.txt to be:

@openzeppelin/=node_modules/@openzeppelin
@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable
forge-std/=node_modules/forge-std/src

then compilation should work

@wshino
Copy link
Author

wshino commented Sep 5, 2024

@koloz193 Thank you so much. Actually we are using the workaround that you posted.

@Jrigada Jrigada closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants