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

Docz does not work if project uses an old version of lodash #1313

Closed
petejodo opened this issue Dec 12, 2019 · 4 comments
Closed

Docz does not work if project uses an old version of lodash #1313

petejodo opened this issue Dec 12, 2019 · 4 comments
Labels
bug Something isn't working v2

Comments

@petejodo
Copy link

Bug Report

Describe the bug
When a project depends on an old version of lodash, e.g. v3.10.1, then running docz commands like docz:dev fail because lodash does not contain a lodash/fp module. This is because the config file gatsby-config.js located in the project root's .docz/ directory resolves to the project's installed lodash version.

On top of that, editing the config to not use lodash/fp doesn't work because the validating of the config file overwrites any changes, causing it to error regardless.

A clear and concise description of what the bug is.

To Reproduce

Please try to build a small repo with a repro of your problem and provide a link to it.

Doing that allows more people to quickly help you.

If you can't provide a repo then provide clear steps describing how to reproduce the issue.

  1. create-react-app my-docz-app && cd my-docz-app
  2. npm i --save lodash@3.10.1 docz
  3. add "docz:dev": "docz dev" as script to package.json
  4. Run npm run docz:dev
  5. See error in browser
> docz dev

Building app

 ERROR #10123  CONFIG

We encountered an error while trying to load your site's gatsby-config. Please fix the error and try again.

  Error: Cannot find module 'lodash/fp'

  - v8-compile-cache.js:159 require
    [my-docz-app]/[gatsby]/[v8-compile-cache]/v8-compile-cache.js:159:20

  - gatsby-config.js:1 Object.<anonymous>
    /.../my-docz-app/.docz/gatsby-config.js:1:85

  - v8-compile-cache.js:178 Module._compile
    [my-docz-app]/[gatsby]/[v8-compile-cache]/v8-compile-cache.js:178:30

  - v8-compile-cache.js:159 require
    [my-docz-app]/[gatsby]/[v8-compile-cache]/v8-compile-cache.js:159:20

  - get-config-file.js:25 getConfigFile
    [my-docz-app]/[gatsby]/dist/bootstrap/get-config-file.js:25:20

  - index.js:129 module.exports
    [my-docz-app]/[gatsby]/dist/bootstrap/index.js:129:13

  - develop.js:419 module.exports
    [my-docz-app]/[gatsby]/dist/commands/develop.js:419:13



not finished open and validate gatsby-configs - 0.078s

Expected behavior

This shouldn't crash because I'm using some unexpected version of lodash.

Environment

  • docz version: 2.2.0
  • OS: OSX 10.14.6
  • Node/npm version: v8.16.0/4.6.1]

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

@petejodo
Copy link
Author

This is also an issue with gatsby-node.js but that one is easier to fix because it could be done via destructuring rather than depending on lodash/get but mergeWith is tricky since it has a lot of logic behind it.

An easy solution could be to export a mergeGatsbyConfig from one of the docz packages that will be known to exist like docz-utils and use that instead

@rakannimer rakannimer added bug Something isn't working v2 labels Dec 13, 2019
@rakannimer
Copy link
Contributor

Hey @petejodo

Thanks for reporting this issue !

I took your suggestion and made docz-utils export lodash/get and lodash/fp/mergeWith.

It should be released with the next docz release. Meanwhile, you can try it out with : yarn add docz@next and it should work as expected 👍

@petejodo
Copy link
Author

petejodo commented Dec 14, 2019

confirmed that this works with docz@2.3.0-alpha.1. Thanks for the quick response and fix @rakannimer!

@maksnester
Copy link

maksnester commented Jul 8, 2020

I have this issue with docz 2.3.1 and fresh install. docz dev fails with

$ docz dev
internal/modules/cjs/loader.js:638
    throw err;
    ^
Error: Cannot find module 'lodash/fp'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (~\my-project\docs\node_modules\load-cfg\dist\index.js:8:10)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Funny that I actually can see node_modules -> lodash -> fp folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2
Projects
None yet
Development

No branches or pull requests

3 participants