Search code examples
node.jstypescriptnpmnode-modulespnpm

node dependencies not found when running pnpm install


I have been using pnpm instead npm for my new projects to try it out and i have ecountered an issue.

I will take my nuxt project as an example.

I first setup my project using the following command:

pnpx nuxi init my-project

I then install a dependency, let's say axios

pnpm add axios

when importing axios in a component i get the following error

import axios from 'axios'
TS7016: Could not find a declaration file for module axios

export default defineNuxtConfig({
    devtools: {enabled: true},
})
TS2552: Cannot find name defineNuxtConfig.

to fix the issue i try to reinstall the dependencies by running pnpm install but the issue remains.

i figured i could fix the issue by running npm install.

For information:

  • commands are ran in a wsl2 environment (Ubuntu)
  • my IDE is Webstorm but the error is also present with VSCode
  • there are also issues with other modules and configuration files such as nuxt.config.ts
  • the issue also happens with React projects
  • the Volar Typescript service specific to Vue is running but the issue is also present with the Main Typescript service

My guess is that my IDE does not know where my node modules are even though the are clearly present in the project but i have no idea to be honst.

Do you have any idea where the issue could come from?


Solution

  • turns out the issue comes from wsl2 that doesn't properly support symlink as of November 2023.

    See: https://youtrack.jetbrains.com/issue/WEB-54790/webstorm-cant-find-any-package-with-pnpm-in-wsl2#focus=Comments-27-5770391.0-0