hardhat-vscode icon indicating copy to clipboard operation
hardhat-vscode copied to clipboard

Hardhat & Dotenv: Cannot find module 'tslib'

Open kalloc opened this issue 1 year ago • 2 comments
trafficstars

I'm trying to use LSP with my Neovim setup and I got an error Cannot find module 'tslib' in one of the projects. After long inspection, I did a small repo that can reproduce the bug. As I learned, the problem was caused by using the typescript hardhat and including dotenv in hardhat.config.ts.

The repo: https://github.com/kalloc/nomicfoundation-solidity-language-server-dotenv-bug

Full trace:

[coc.nvim] Hardhat project 'bug-tslib-error' was not able to initialize correctly:
 Cannot find module 'tslib'
Require stack:
- /home/y/work/bug-tslib-error/hardhat.config.ts
- /home/y/work/bug-tslib-error/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/hardhat/internal/core/config/config-loading.js
- /home/y/work/work/bug-tslib-error/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/hardhat/register.js
- /home/y/.nvm/versions/node/v18.12.1/lib/node_modules/@ignored/solidity-language-server/out/worker/WorkerProcess.js

LSP Trace: https://gist.github.com/kalloc/3f971ac9c0be79c1ae775457d108b6e0

kalloc avatar Dec 17 '23 18:12 kalloc

How I use LSP

…
        "solidity": {
            "command": "nomicfoundation-solidity-language-server",
            "trace.server": "verbose",
            "trace.server.format": "json",
            "args": [
                "--stdio"
            ],
            "filetypes": [
                "solidity"
            ],
            "rootPatterns": [
                "foundry.toml",
                "package.json",
                ".git"
            ],
        }
…

kalloc avatar Dec 17 '23 18:12 kalloc

The solution for me is to install tslib (pnpm add tslib -D), but I think if hardhat (pnpm run compile) works, LSP should work too.

kalloc avatar Dec 17 '23 19:12 kalloc