我正在制作一个使用 d3 的包。当然,在我的 rollup.config.js
文件中,我将 d3
声明为外部包和全局包:
let config = {
...,
output: {
external: ['d3'],
globals: {d3:'d3'},
...,
},
...
}
我可能在某个文件中有一个函数,例如:
import * as d3 from 'd3'
...
export function someFunc(arg1, arg2) {
d3.select(arg1)
d3.min(arg2)
}
...
当我将代码与 rollup -c
捆绑在一起时,我收到了很好的警告
src/modules/some-file.js
selection is not exported by node_modules/d3/dist/d3.node.js
所以我回到我的 rollup.config.js
文件并添加以下内容:
// inside config
plugins: [
...,
commonjs({
...,
namedExports: {
'node_modules/d3/dist/d3.node.js': [
'selection', 'min',
]
},
...,
})
...,
]
现在我的 bundle 没有警告或投诉...但是当我使用捆绑的代码时,我收到如下错误:
TypeError: d3_node_1 is null
TypeError: d3_node_2 is null
其中 d3_node_1
出现在我的代码中有 d3.select
的位置,d3_node_2
出现在 d3.min
的位置是。
我该如何解决这个问题?
最佳答案
您可能必须使用 rollup-plugin-node-resolve使用node_modules中的第三方模块
关于javascript - d3 的 Rollup 命名导出问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57090509/