NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code
https://hardhat.org
MIT License
163 stars 36 forks source link

Hardhat & Dotenv: Cannot find module 'tslib' #536

Open kalloc opened 6 months ago

kalloc commented 6 months ago

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/hardhat@2.14.1_ts-node@10.9.1_typescript@5.1.6/node_modules/hardhat/internal/core/config/config-loading.js
- /home/y/work/work/bug-tslib-error/node_modules/.pnpm/hardhat@2.14.1_ts-node@10.9.1_typescript@5.1.6/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 commented 6 months ago

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 commented 6 months ago

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.