简体   繁体   中英

Error: Cannot find module 'loopback' in nodejs

I am facing below issue and unable to figure out the root cause.

Error: Cannot find module 'loopback'

Below are the dependencies I have in my package.json

"loopback": "^3.19.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^6.0.0",
"loopback-connector-postgresql": "^2.9.0"

First I did npm i and then node .

But it throws an error Cannot find module 'loopback'

Don't understand why this is behaving differently. Please suggest

Edit: My all modules are found under

    > node_modules
      > .staging
        > //loopback modules and other modules are placed under .staging but not sure why. 

The fact that your dependencies are inside the staging directory and not the main node_modules directory imply that something went wrong with the download/installation process and your dependencies are not installed properly. And hence you get the 'Could not find module' error.

Try the following steps -

  1. Delete package-lock.json
  2. Delete Node Modules folder
  3. Do a npm install to install packages listed in package.json

Once the installation is complete, all your node dependencies should be inside your node_modules folder.

It might also be worth checking to see if you have more than one node version on your machine. That could cause similar problems as well.

use

npm config set user 0
npm config set unsafe-perm true

npm install -g loopback-cli
npm install

https://loopback.io/doc/en/lb3/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM