title: d3 and webpack: __WEBPACK_IMPORTED_MODULE_0_d3__.scaleLinear is not a function
body: <p>I'm attempting to use d3 to render some graphs in my Vuejs components. I am importing d3 as recommended <code>import * as d3 from 'd3'</code> and attempting to call d3 functions on it.</p>
  
  <p>webpack.base.conf.js</p>
  
  <pre><code>'use strict'
  const path = require('path')
  const utils = require('./utils')
  const config = require('../config')
  const vueLoaderConfig = require('./vue-loader.conf')
  
  function resolve (dir) {
    return path.join(__dirname, '..', dir)
  }
  
  const createLintingRule = () =&gt; ({
    test: /\.(js|vue)$/,
    loader: 'eslint-loader',
    enforce: 'pre',
    include: [resolve('src'), resolve('test')],
    options: {
      formatter: require('eslint-friendly-formatter'),
      emitWarning: !config.dev.showEslintErrorsInOverlay
    }
  })
  
  module.exports = {
    context: path.resolve(__dirname, '../'),
    entry: {
      app: './src/main.js'
    },
    output: {
      path: config.build.assetsRoot,
      filename: '[name].js',
      publicPath: process.env.NODE_ENV === 'production'
        ? config.build.assetsPublicPath
        : config.dev.assetsPublicPath
    },
    resolve: {
      extensions: ['.js', '.vue', '.json'],
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': resolve('src'),
        'src': resolve('src'),
        'components': resolve('src/components'),
        'assets': resolve('src/assets'),
        'static': resolve('static'),
        'styles': resolve('src/styles')
      }
    },
    module: {
      rules: [
        ...(config.dev.useEslint ? [createLintingRule()] : []),
        {
          test: /\.vue$/,
          loader: 'vue-loader',
          options: vueLoaderConfig
        },
        {
          test: /\.js$/,
          loader: 'babel-loader',
          include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
        },
        {
          test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
          loader: 'url-loader',
          options: {
            limit: 10000,
            name: utils.assetsPath('img/[name].[hash:7].[ext]')
          }
        },
        {
          test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
          loader: 'url-loader',
          options: {
            limit: 10000,
            name: utils.assetsPath('media/[name].[hash:7].[ext]')
          }
        },
        {
          test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
          loader: 'url-loader',
          options: {
            limit: 10000,
            name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
          }
        },
      ]
    },
    node: {
      // prevent webpack from injecting useless setImmediate polyfill because Vue
      // source contains it (although only uses it if it's native).
      setImmediate: false,
      // prevent webpack from injecting mocks to Node native modules
      // that does not make sense for the client
      dgram: 'empty',
      fs: 'empty',
      net: 'empty',
      tls: 'empty',
      child_process: 'empty'
    }
  }
  </code></pre>
  
  <p>.babelrc</p>
  
  <pre><code>{
    "presets": [
      ["env", {
        "modules": false,
        "targets": {
          "browsers": ["&gt; 1%", "last 2 versions", "not ie &lt;= 8"]
        }
      }],
      "stage-2"
    ],
    "plugins": [
      "dynamic-import-node",
      "syntax-dynamic-import",
      "transform-runtime"
    ],
    "env": {
      "test": {
        "presets": [
          [ "env", { "targets": { "node": 8}}],
        ],
        "plugins": ["transform-es2015-modules-commonjs", "dynamic-import-node"]
      }
    }
  }
  </code></pre>
  
  <p>Error from the console: <code>Vue warn]: Error in mounted hook: "TypeError: __WEBPACK_IMPORTED_MODULE_0_d3__.scaleLinear is not a function"</code></p>
  
  <p>Component using d3:</p>
  
  <pre><code>import * as d3 from 'd3'
  const graphW = '200'
  const graphH = '30'
  const xDomain = [1, 10]
  const xRange = [0, 200]
  const yRange = [30, 0]
  
  export default {
      ...
      methods: {
          render: function () {
              var self = this
              var graph = d3.select('.' + self.className).append('svg:svg').attr('width', graphW).attr('height', graphH)
              var data = self.data
  
              var x = d3.scaleLinear().domain(xDomain).range(xRange)
              var y = d3.scaleLinear().domain([d3.min(data), d3.max(data)]).range(yRange)
      ...
  </code></pre>