'Truffle init returns cannot find module

After installing nodejs, I created a directory, installed truffle, but after typing the command truffle init it returns this error. I've tried everything, but this doesn't go away. I've reinstalled yet it's the same. How do I fix this?

node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\Users\lawrence david\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}


Solution 1:[1]

I've solved the issue. All you need to do is to run "npm install -g [email protected]" This will install an older version of truffle. Turns out the issue is with "npm install -g truffle" since it installs the latest version, and the latest version is currently having glitches.

Just run "npm install -g [email protected]" or an older version of truffle and your issue will be solved.

Solution 2:[2]

Delete node_modules and run npm install again

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dayvvid
Solution 2 Daniel Barbosa de Lima