Javascript (!)未使用的外部导入';减少';从外部模块导入';洛达斯';但从未使用过

Javascript (!)未使用的外部导入';减少';从外部模块导入';洛达斯';但从未使用过,javascript,import,lodash,node-modules,rollupjs,Javascript,Import,Lodash,Node Modules,Rollupjs,我正在使用rollup构建我的库,并且我依赖于lodash 但是当我运行rollup捆绑我的代码时,我得到了这个警告 (!) Unused external imports reduce imported from external module 'lodash' but never used 我的代码示例如下所示: import { reduce } from "lodash" export function someutilityfunction(args) { return r

我正在使用
rollup
构建我的库,并且我依赖于
lodash

但是当我运行
rollup
捆绑我的代码时,我得到了这个警告

(!) Unused external imports
reduce imported from external module 'lodash' but never used
我的代码示例如下所示:

import { reduce } from "lodash"

export function someutilityfunction(args) {
    return reduce(args,() => {
        // do somthing
    }, {}) // A generic use case of reduce function
}
捆绑的库运行良好

我甚至试过使用

import * as _ from "lodash"
lodash es
而不是
lodash

但是没有成功

这是我的rollup.config.js

我以前使用过这个汇总配置,到现在为止,它工作得很好

我错过什么了吗


我知道问题的标题可以更一般。请随意改进帖子。

看起来Rollup和Lodash中的树抖动存在已知问题(D3也有类似问题):


我曾想过使用
babel插件lodash
,但最终决定使用
const{reduce}=require(“lodash”)
@th3n3wguy
import resolve      from 'rollup-plugin-node-resolve'
import babel        from 'rollup-plugin-babel'
import filesize     from 'rollup-plugin-filesize'
import typescript   from 'rollup-plugin-typescript2'
import commonjs     from 'rollup-plugin-commonjs'
import uglify       from 'rollup-plugin-uglify'

let production = (process.env.NODE_ENV == "production")

export default {
    input: 'src/index.ts',
    output: {
        file: 'lib/index.js',
        format: 'cjs',
        name: 'my-library',
        sourcemap: true
    },
    external: [
        'rxjs',
        'axios',
        'lodash'
    ],
    plugins: [
        resolve(),
        typescript({
            tsconfigOverride: {
                compilerOptions: {
                    declaration: true,
                    moduleResolution: "node",
                    allowSyntheticDefaultImports: true
                }
            },
            // verbosity: 3,
            clean: true,
            rollupCommonJSResolveHack: true,
            abortOnError: false,
            typescript: require('typescript'),
        }),
        commonjs(),   
        babel({
            exclude: 'node_modules/**'
        }),
        production && uglify(),
        filesize()
    ],
    watch: {
        include: 'src/**'
    }
  };