question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NVM environment variables - Error loading node module, Cannot find module

See original GitHub issue

Installed the extension and installed prettier globally.

user@host:~$ which prettier
/home/user/.nvm/versions/node/v14.16.0/bin/prettier
user@host:~$ echo $NVM_BIN
/home/user/.nvm/versions/node/v14.16.0/bin
user@host:~$ cd $NVM_BIN/../lib/node_modules/prettier/
user@host:~/.nvm/versions/node/v14.16.0/lib/node_modules/prettier$ ls
LICENSE          esm                parser-babel.js    parser-graphql.js   parser-postcss.js     third-party.js
README.md        index.js           parser-espree.js   parser-html.js      parser-typescript.js
bin-prettier.js  package.json       parser-flow.js     parser-markdown.js  parser-yaml.js
doc.js           parser-angular.js  parser-glimmer.js  parser-meriyah.js   standalone.js

But when setting prettier.prettierPath as $NVM_BIN/../lib/node_modules/prettier/ in VS Code settings, I end up with:

["ERROR" - timestamp] Error loading node module '/home/user/projectFolder/lib/node_modules/prettier/'
["ERROR" - timestamp] Cannot find module '/home/user/projectFolder/lib/node_modules/prettier/'

Instead, if I put ~/.nvm/versions/node/v14.16.0/lib/node_modules/prettier, I end up with:

["ERROR" - timestamp] Error loading node module '/home/user/projectFolder/~/.nvm/versions/node/v14.16.0/lib/node_modules/prettier'
["ERROR" - timestamp] Cannot find module '/home/user/projectFolder/~/.nvm/versions/node/v14.16.0/lib/node_modules/prettier'

Putting /home/user/.nvm/versions/node/v14.16.0/lib/node_modules/prettier works but defeats the purpose of using NVM. I am not able to use environment variables in the path. It always seems to be adding the project folder path at the beginning of whatever I put. Am I doing it wrong or is it a bug?

OS: Windows 10 21H1 (19043.1052) + WSL 2 running Ubuntu 21.04 VS Code: 1.57.1 system setup prettier global version: 2.3.1 prettier-vscode version: 8.0.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aravindvnair99commented, Jun 29, 2021

Thank you for the explanation @ntotten! Appreciate your time and I have understood everything you said. Will rework my setup based on your inputs.

0reactions
github-actions[bot]commented, Sep 29, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: cannot find module [Node npm Error Solved]
When you get the “cannot find module” error, or “module not found”, it means you've not installed the package you're trying to use....
Read more >
NPM global install "cannot find module" - node.js
For anyone else running into this, I had this problem due to my npm installing into a location that's not on my NODE_PATH...
Read more >
Cannot find module 'node:path' in vite.config.ts · Issue ...
The error is Error: Cannot find module 'node:path' which seems to mean that the build isn't running in a node environment.
Read more >
Error NPM global install cannot find module
Set the Windows environment variable for NODE_PATH. This path is where your packages are installed. It's probably something likeNODE_PATH = C:\ ...
Read more >
internal modules cjs loader error - You.com | The AI Search ...
1 Answer. Sorted by: 1. The issue was due to the wrong path of node in system variable. changing it from to C:\Program...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found