Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'lodash' #50

Closed
luca-nardelli opened this issue Mar 18, 2019 · 7 comments
Closed

Cannot find module 'lodash' #50

luca-nardelli opened this issue Mar 18, 2019 · 7 comments
Labels

Comments

@luca-nardelli
Copy link
Contributor

I've tried to run the command through npx on my machine but it doesn't work.

$ npx @api-platform/client-generator
npx: installed 284 in 10.132s
Cannot find module 'lodash'

If I install the package globally I get the following error

$ generate-api-platform-client 
internal/modules/cjs/loader.js:615
    throw err;
    ^

Error: Cannot find module 'lodash'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:613:15)
    at Function.Module._load (internal/modules/cjs/loader.js:539:25)
    at Module.require (internal/modules/cjs/loader.js:667:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/luca/.nvm/versions/node/v11.10.0/lib/node_modules/@api-platform/client-generator/node_modules/@api-platform/api-doc-parser/lib/swagger/handleJson.js:48:15)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)

However, I can solve this by globally installing lodash

@dunglas
Copy link
Member

dunglas commented Mar 19, 2019

It’s weird because lodash isn’t used in the command (it is only in the generated code).

@luca-nardelli
Copy link
Contributor Author

Checking the stacktrace:

at Object.<anonymous> (/home/luca/.nvm/versions/node/v11.10.0/lib/node_modules/@api-platform/client-generator/node_modules/@api-platform/api-doc-parser/lib/swagger/handleJson.js:48:15)

I went to api-doc-parser: https://github.com/api-platform/api-doc-parser/blob/master/src/swagger/handleJson.js

Here it imports lodash, so probably the issue is there?

@dunglas
Copy link
Member

dunglas commented Mar 29, 2019

I can confirm that this bug occurs time to time when using Docker. Rebuilding the Docker container fixed the issue in my case. It needs more investigation, but it's probably not directly related to this repository.

@luca-nardelli
Copy link
Contributor Author

In my case, it happened on my pc (without being in a docker container), and it seemed to always happen unless I had globally installed lodash by myself.

Sorry if this seems a repetition of what I wrote above, but I didn't understand if you excluded the issue being in api-doc-parser or not, so I'll rephrase what I wrote.

The error trace I printed above points to the handleJson.js in api-doc-parser.

Line 1 is
import { get, uniq } from "lodash";

However, in the package.json only lodash.get is listed as a dependency. Can this be related?

@dunglas
Copy link
Member

dunglas commented Mar 30, 2019

Good catch thanks for investigating! lodash.uniq must be added to api-doc-parser's package.json! Would you mind to open a Pull Request? (I move this issue to the appropriate repository).

@dunglas dunglas transferred this issue from api-platform/create-client Mar 30, 2019
@dunglas dunglas added the bug label Mar 30, 2019
@luca-nardelli
Copy link
Contributor Author

Yeah I'll do that!

@luca-nardelli
Copy link
Contributor Author

Opened the PR: #51

I had to add lodash.uniq as a dependency and also change how the two functions were imported, since lodash is not listed in the package.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants