babel-plugin-lodash icon indicating copy to clipboard operation
babel-plugin-lodash copied to clipboard

import { type T } from 'non-lodash'

Open ckknight opened this issue 6 years ago • 7 comments

Although I can't seem to reproduce this with the lodash module, it affects others. I suspect that has to do with the differentiation between pkgStores where .isLodash() is used to differentiate.

Using the following .babelrc

{
  "plugins": [
    ["lodash", { "id": ["lodash", "recompose"] }]
  ],
  "presets": [
    ["env", { "targets": { "node": 6 } }]
  ]
}
import { type HOC } from 'recompose';

Throws the following error: SyntaxError: The 'recompose' method `HOC` is not a known module.

A workaround

import type { HOC } from 'recompose';

works as expected, but has the downside of not being able to import functions and types simultaneously.

ckknight avatar Jul 21 '17 22:07 ckknight

Hi @ckknight!

Is that typing TypeScript or Flow?

jdalton avatar Jul 22 '17 00:07 jdalton

Flow

ckknight avatar Aug 08 '17 18:08 ckknight

I have similar issue with babel@^7-beta.40 1.

import type {HOC} from 'recompose';

causes

ERROR in ./src/app/agree/containers/Agree.jsx
Module build failed: TypeError: Cannot read property 'path' of undefined
    at .../node_modules/babel-plugin-lodash/lib/index.js:228:47
    at arrayEach (....node_modules/lodash/_arrayEach.js:15:9)

with


import { type HOC } from 'recompose';

pp/agree/containers/Agree.jsx: The 'recompose' method `HOC` is not a known module.
Please report bugs to https://github.com/lodash/babel-plugin-lodash/issues.


basic babelrc config to reproduce


const presets = [
    // bread and butter
    [
      require('@babel/preset-env').default,
      {
        shippedProposals: true,
        loose: true,
        useBuiltIns: 'entry',
        ...(rest || {}),
        modules:
          rest.modules ||
          (target === 'web' || target === 'client' ? false : 'commonjs'),
      },
    ],
    require('@babel/preset-react').default,
    // flow since no longer in react
    // react
    require('@babel/preset-flow').default,
  ];
const plugins = [
    [
      "babel-plugin-lodash",
      {
        id: [
          "lodash",
          "recompose",
        ]
      }
    ];
module.exports = { presets, plugins };

I believe this issue may be related https://github.com/babel/babel/issues/7233

dlebedynskyi avatar Mar 11 '18 01:03 dlebedynskyi

I have related issue with TypeScript:

import { Dictionary } from 'lodash';
type ColumnIndexes = Dictionary<number>;
ERROR in ./node_modules/@ihme/common/utility/data/index.ts
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/piotrek/Make/ihme-gilead/node_modules/@ihme/common/utility/data/index.ts: The 'lodash' method `Dictionary` is not a known module.
Please report bugs to https://github.com/lodash/babel-plugin-lodash/issues.
...
> 13 | type ColumnIndexes = Dictionary<number>;

piotrwitek avatar Nov 15 '18 11:11 piotrwitek

I have a similar issue with typescript and import { Cancelable } from 'lodash';

Is there a way to configure a set of modules for which errors should be ignored?

sarod avatar Jan 25 '19 08:01 sarod

For anyone searching for a workaround I'm currently using this plugin: https://www.npmjs.com/package/babel-plugin-transform-imports

I'm able to import { Dictionary } from 'lodash' with no errors.

knpwrs avatar Mar 13 '19 19:03 knpwrs

I have related issue with TypeScript:

import { Dictionary } from 'lodash';
type ColumnIndexes = Dictionary<number>;
ERROR in ./node_modules/@ihme/common/utility/data/index.ts
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/piotrek/Make/ihme-gilead/node_modules/@ihme/common/utility/data/index.ts: The 'lodash' method `Dictionary` is not a known module.
Please report bugs to https://github.com/lodash/babel-plugin-lodash/issues.
...
> 13 | type ColumnIndexes = Dictionary<number>;

Hi, I appreciate if anyone tells me this issue status. Is it solved?

phatpt8 avatar Jun 10 '19 07:06 phatpt8