汇总:"Import of non-existent export" 从 Lodash 导入函数时
Rollup: "Import of non-existent export" when importing function from Lodash
我有一个小型库,它使用 Rollup 捆绑为 UMD 模块。我正在尝试将一个函数从 Lodash 导入到我的库中,但出现错误。
我尝试像这样导入函数:
import { partition } from 'lodash';
我得到这个错误:
(!) Import of non-existent export
src/main.js
1: import { partition } from 'lodash';
这是我的汇总配置:
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
export default {
input: 'src/main.js',
output: {
file: 'dist/browser-metrics.js',
name: 'BrowserMetrics',
format: 'umd'
},
plugins: [
resolve(),
babel({
exclude: 'node_modules/**'
})
]
};
知道我做错了什么吗?
安装并使用具有 es6 import/export 功能的 lodash-es
模块
npm install lodash-es
然后
import { partition } from 'lodash-es';
或
import partition from 'lodash-es/partition';
最好仍然使用 'lodash' 并使用 @rollup/plugin-commonjs and babel-plugin-lodash 来处理 'cjs -> esm' 转换和 tree-shaking。
有很多流行的 NPM 包导出为 'cjs'。在源代码级别从 'name' 切换到 'name-es' 的工作将是巨大而烦人的。
我有一个小型库,它使用 Rollup 捆绑为 UMD 模块。我正在尝试将一个函数从 Lodash 导入到我的库中,但出现错误。
我尝试像这样导入函数:
import { partition } from 'lodash';
我得到这个错误:
(!) Import of non-existent export
src/main.js
1: import { partition } from 'lodash';
这是我的汇总配置:
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
export default {
input: 'src/main.js',
output: {
file: 'dist/browser-metrics.js',
name: 'BrowserMetrics',
format: 'umd'
},
plugins: [
resolve(),
babel({
exclude: 'node_modules/**'
})
]
};
知道我做错了什么吗?
安装并使用具有 es6 import/export 功能的 lodash-es
模块
npm install lodash-es
然后
import { partition } from 'lodash-es';
或
import partition from 'lodash-es/partition';
最好仍然使用 'lodash' 并使用 @rollup/plugin-commonjs and babel-plugin-lodash 来处理 'cjs -> esm' 转换和 tree-shaking。 有很多流行的 NPM 包导出为 'cjs'。在源代码级别从 'name' 切换到 'name-es' 的工作将是巨大而烦人的。