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

Missing lodash dependency for admin js package #2264

Closed
afdev82 opened this issue Mar 16, 2022 · 2 comments · Fixed by #2268
Closed

Missing lodash dependency for admin js package #2264

afdev82 opened this issue Mar 16, 2022 · 2 comments · Fixed by #2268

Comments

@afdev82
Copy link
Contributor

afdev82 commented Mar 16, 2022

Steps to reproduce

Precompile the assets with RAILS_ENV=production bin/rake assets:precompile

Expected behavior

No error when precompiling the assets.

Actual behavior

I get the following error:

COMPILATION FAILED:
EXIT STATUS: pid 19245 exit 2
OUTPUTS:
[webpack-cli] ModuleNotFoundError: Module not found: Error: Can't resolve 'lodash/debounce' in '/home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/admin/package/src'
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/Compilation.js:2015:28
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/home/antonio/Projects/SmartMirror/Server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/home/antonio/Projects/SmartMirror/Server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /home/antonio/Projects/SmartMirror/Server/node_modules/webpack/lib/NormalModuleFactory.js:975:5
resolve 'lodash/debounce' in '/home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/admin/package/src'
  Parsed request is a module
  using description file: /home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/admin/package.json (relative path: ./package/src)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      looking for modules in /home/antonio/Projects/SmartMirror/Server/app/frontend
        /home/antonio/Projects/SmartMirror/Server/app/frontend/lodash doesn't exist
      /home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/admin/package/src/node_modules doesn't exist or is not a directory
      /home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/admin/package/node_modules doesn't exist or is not a directory
      /home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/admin/node_modules doesn't exist or is not a directory
      /home/antonio/Projects/SmartMirror/Server/node_modules/@alchemy_cms/node_modules doesn't exist or is not a directory
      /home/antonio/Projects/SmartMirror/Server/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /home/antonio/Projects/SmartMirror/Server/node_modules
        /home/antonio/Projects/SmartMirror/Server/node_modules/lodash doesn't exist
      /home/antonio/Projects/SmartMirror/node_modules doesn't exist or is not a directory
      /home/antonio/Projects/node_modules doesn't exist or is not a directory
      /home/antonio/node_modules doesn't exist or is not a directory
      /home/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

System configuration

  • Alchemy Version: 6.0.0.pre.rc6
  • Rails Version: 6.1.5

I see a dependency from lodash-es instead of lodash, maybe is it enough to require a different module here or adding the lodash dependency here? I can create a PR once agree on the direction to fix this issue.
In development it's fine because I have other packages that depends on lodash, so the package is there anyway in the node_modules directory.

@tvdeyen
Copy link
Member

tvdeyen commented Mar 17, 2022

lodash-es is the ES module package version of lodash. With that we are able to import just the module we need.
I never had such issues in any of the apps I maintain. And our CI also passes. So, I assume this is something else.

Can you try to provide a demo app where this error happens?

@afdev82
Copy link
Contributor Author

afdev82 commented Mar 18, 2022

Yes, I can provide a demo app: https://github.com/adnotam/dummy_cms_app/blob/master/package.json
I don't have this error in another app I maintain, because the lodash package gets added by another dependency.
In case of the demo app, it's working only because of webpacker:

$ yarn why lodash
yarn why v1.22.17
[1/4] Why do we have the module "lodash"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "lodash@4.17.21"
info Reasons this module exists
   - "webpack-dev-server#http-proxy-middleware" depends on it
   - Hoisted from "webpack-dev-server#http-proxy-middleware#lodash"
   - Hoisted from "webpack-dev-server#portfinder#async#lodash"
   - Hoisted from "@rails#webpacker#optimize-css-assets-webpack-plugin#last-call-webpack-plugin#lodash"
info Disk size without dependencies: "4.88MB"
info Disk size with unique dependencies: "4.88MB"
info Disk size with transitive dependencies: "4.88MB"
info Number of shared dependencies: 0
Done in 0.44s.

But Alchemy is dependent on lodash-es:

$ yarn why lodash-es
yarn why v1.22.17
[1/4] Why do we have the module "lodash-es"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "lodash-es@4.17.21"
info Reasons this module exists
   - "@alchemy_cms#admin" depends on it
   - Hoisted from "@alchemy_cms#admin#lodash-es"
info Disk size without dependencies: "2.59MB"
info Disk size with unique dependencies: "2.59MB"
info Disk size with transitive dependencies: "2.59MB"
info Number of shared dependencies: 0
Done in 0.42s.

So I wonder why not using lodash-es, the import is still using lodash:

import debounce from "lodash-es/debounce"
import max from "lodash-es/max"

Instead of

import debounce from "lodash/debounce"
import max from "lodash/max"

Now I realize that I have the problem because I don't have webpacker anymore, at the moment I'm using shakapacker with a forked version of Alchemy. Anyway I think it's a problem, just "hidden" by webpacker at the moment, that's why I think it's ok to have opened the issue here.

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

Successfully merging a pull request may close this issue.

2 participants