segmentio / consent-manager

Drop-in consent management plugin for analytics.js
https://segmentio.github.io/consent-manager/
MIT License
341 stars 142 forks source link

Lodash Dependency issue #233

Closed timofei-iatsenko closed 2 years ago

timofei-iatsenko commented 2 years ago

src/consent-manager-builder/fetch-destinations.ts

import flatten from 'lodash/flatten'
import sortedUniqBy from 'lodash/sortedUniqBy'
import sortBy from 'lodash/sortBy'

package.json

"dependencies": {
    "@emotion/react": "^11.8.2",
    "@emotion/styled": "^11.8.1",
    "@segment/in-regions": "^1.2.0",
    "@segment/top-domain": "^3.0.0",
    "emotion": "^9.1.2",
    "isomorphic-fetch": "^3.0.0",
    "js-cookie": "^2.2.0",
    "lodash-es": "^4.17.10", <-- !!!
    "nanoid": "^1.0.2",
    "prop-types": "^15.6.1"
  },

Result:

Cannot find module 'lodash/flatten' Require stack:

  • /app/node_modules/@segment/consent-manager/commonjs/consent-manager-builder/fetch-destinations.js
  • /app/node_modules/@segment/consent-manager/commonjs/consent-manager-builder/index.js
  • /app/node_...

lodash-es doesn't provide all this subpackages, and it doesn't depend on original lodash either, so it works in some cases only because one of transient dependencies also depend on regular lodash.

lodash-es/package.json

{
  "name": "lodash-es",
  "version": "4.17.21",
  "description": "Lodash exported as ES modules.",
  "keywords": "es6, modules, stdlib, util",
  "homepage": "https://lodash.com/custom-builds",
  "bugs": "https://github.com/lodash/lodash-cli/issues",
  "repository": "lodash/lodash",
  "license": "MIT",
  "type": "module",
  "jsnext:main": "lodash.js",
  "main": "lodash.js",
  "module": "lodash.js",
  "sideEffects": false,
  "author": "John-David Dalton <john.david.dalton@gmail.com>",
  "contributors": [
    "John-David Dalton <john.david.dalton@gmail.com>",
    "Mathias Bynens <mathias@qiwi.be>"
  ],
  "scripts": { "test": "echo \"See https://travis-ci.org/lodash-archive/lodash-cli for testing details.\"" }
}