🏠 back to Observable

Using d3-selection-multi

I’d like to use https://github.com/d3/d3-selection-multi within Observable notebooks. Is there a way to import the standard d3 bundle together with d3-selection-multi?

The advice in this thread works for requiring d3-selection and d3-selection-multi, but require('d3', 'd3-selection-multi') doesn’t seem to work even though require('d3-selection', 'd3-selection-multi') does.

Test notebook: https://observablehq.com/d/0d730877fb8fac98

I tried using the require debugger but it doesn’t look like the issue is with importing the module.

You need to tell require where to find d3-selection (and d3-transition). Without that, it doesn’t realize that the d3 module defines d3-selection and d3-transition, and so you get duplicate copies of the modules. I sent you a suggestion:

d3 = require.alias({
  'd3-selection': 'd3',
  'd3-transition': 'd3'
})('d3', 'd3-selection-multi')
2 Likes

Awesome, thanks Mike!

For future readers, this guide is a great introduction to the basics of require, and here’s the full documentation for the d3-require module.

1 Like