loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.96k stars 1.07k forks source link

Error Cannot find module 'fs-extra' #2272

Closed agung-wete closed 5 years ago

agung-wete commented 5 years ago

Description / Steps to reproduce / Feature proposal

run command lb4 example

Current Behavior

Error: Cannot find module 'fs-extra'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)

Expected Behavior

Same as doc https://loopback.io/doc/en/lb4/Examples-and-tutorials.html

Using Window, here is lb4 -v output:

@loopback/cli version: 1.5.1

@loopback/* dependencies:
  - @loopback/authentication: ^1.0.10
  - @loopback/boot: ^1.0.10
  - @loopback/build: ^1.2.0
  - @loopback/context: ^1.4.1
  - @loopback/core: ^1.1.4
  - @loopback/metadata: ^1.0.4
  - @loopback/openapi-spec-builder: ^1.0.4
  - @loopback/openapi-v3-types: ^1.0.4
  - @loopback/openapi-v3: ^1.1.7
  - @loopback/repository-json-schema: ^1.2.7
  - @loopback/repository: ^1.1.3
  - @loopback/rest: ^1.5.3
  - @loopback/testlab: ^1.0.4
  - @loopback/docs: ^1.7.1
  - @loopback/example-hello-world: ^1.1.1
  - @loopback/example-log-extension: ^1.1.1
  - @loopback/example-rpc-server: ^1.1.0
  - @loopback/example-todo: ^1.4.1
  - @loopback/example-soap-calculator: ^1.3.1
  - @loopback/service-proxy: ^1.0.6
  - @loopback/http-caching-proxy: ^1.0.4
  - @loopback/http-server: ^1.1.3
  - @loopback/example-todo-list: ^1.4.1
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^1.1.6
  - @loopback/tslint-config: ^2.0.0
bajtos commented 5 years ago

I am afraid I am not able to reproduce the issue locally.

$ lb4 example
? What example would you like to clone? todo
added 615 packages from 1442 contributors and audited 3849 packages in 13.037s
found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

The example was cloned to loopback4-example-todo.

Can you try to reinstall @loopback/cli?

For example:

$ npm uninstall -g @loopback/cli
$ npm install -g @loopback/cli
agung-wete commented 5 years ago

After uninstall and reinstall, same error, here is the full error message of lb4 example command :

module.js:550
    throw err;
    ^

Error: Cannot find module 'fs-extra'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\XXX\AppData\Roaming\npm\node_modules\@loopback\cli\generators\example\index.js:13:12)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.get [as loopback4:example] (C:\Users\xxx\AppData\Roaming\npm\node_modules\@loopback\cli\node_modules\yeoman-environment\lib\store.js:39:27)
    at Store.get (C:\Users\xxx\AppData\Roaming\npm\node_modules\@loopback\cli\node_modules\yeoman-environment\lib\store.js:62:39)
    at Environment.get (C:\Users\xxx\AppData\Roaming\npm\node_modules\@loopback\cli\node_modules\yeoman-environment\lib\environment.js:342:23)
    at Environment.create (C:\Users\xxx\AppData\Roaming\npm\node_modules\@loopback\cli\node_modules\yeoman-environment\lib\environment.js:376:28)

lb4 -v

@loopback/cli version: 1.5.1

@loopback/* dependencies:
  - @loopback/authentication: ^1.0.10
  - @loopback/boot: ^1.0.10
  - @loopback/build: ^1.2.0
  - @loopback/context: ^1.4.1
  - @loopback/core: ^1.1.4
  - @loopback/metadata: ^1.0.4
  - @loopback/openapi-spec-builder: ^1.0.4
  - @loopback/openapi-v3-types: ^1.0.4
  - @loopback/openapi-v3: ^1.1.7
  - @loopback/repository-json-schema: ^1.2.7
  - @loopback/repository: ^1.1.3
  - @loopback/rest: ^1.5.3
  - @loopback/testlab: ^1.0.4
  - @loopback/docs: ^1.7.1
  - @loopback/example-hello-world: ^1.1.1
  - @loopback/example-log-extension: ^1.1.1
  - @loopback/example-rpc-server: ^1.1.0
  - @loopback/example-todo: ^1.4.1
  - @loopback/example-soap-calculator: ^1.3.1
  - @loopback/service-proxy: ^1.0.6
  - @loopback/http-caching-proxy: ^1.0.4
  - @loopback/http-server: ^1.1.3
  - @loopback/example-todo-list: ^1.4.1
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^1.1.6
  - @loopback/tslint-config: ^2.0.0
pramod-dev commented 4 years ago

I had the same issue.

Cannot find module 'module_name'

Error: Cannot find module 'module_name'

When I run the command:

npm install --save module_name

Note: Here the 'module_name' is the name of the missing module. example: fs-extra, glob, dependency-graph, sort-package-json, @phosphor/coreutils, prettier etc.

It throws a new error that a new module is missing. And it kept happening everytime I try to fix an error, a new error pops up the next time(other packages mentioned above).

Here's what I did to solve the error:

I had to uninstall and unlink nodejs and npm : Note: use unlink only if you have linked them before, otherwise, it's not necessary

brew uninstall node

brew unlink node

brew unlink npm

brew unlink node_modules

Make sure you remove all the node_modules, npm and nodejs folders from your system. My commands below can be different from yours. You can manually search for folders and remove them as well:

rm -rf /usr/local/lib/node_modules

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm,node,man1/node*}

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp

After uninstalling and deleting all node, npm folders, I ran these commands:

brew install node

npm install yarn -g

npm install -g typescript

npm install

yarn install

That fixed all the issues