A
A
AgentToxa2018-08-24 16:36:16
webpack
AgentToxa, 2018-08-24 16:36:16

How to fix the error when trying to include a built vue component: "export 'default' was not found in?

Written a simple single-file component in Vue JS. The interest is to assemble it using Webpack into one js executable file, which can then be included using import in other vue components.
For example, here is our test.vue component:

<template>
  <div @click="clickButton">TEST</div>
</template>

<script>
  export default {
    name: 'test',

    methods: {
      clickButton () {
        console.log('на кнопку нажали')
      }
    }
  }
</script>

using Webpack I collect it in test.js.
Here is the webpack config:
"use strict"

var path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
  entry: {
    test: './src/components/test.vue'
  },
  output: {
    path: path.resolve(__dirname, './lib/components'),
    publicPath: '/lib/',
    filename: '[name].js',
    chunkFilename: '[id].js',
    libraryTarget: 'commonjs2'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          preserveWhitespace: false
        }
      },
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: 'env'
          }
        },
        exclude: /node_modules/
      },
    ]
  },
  plugins: [
    new VueLoaderPlugin()
  ]
}

The file is successfully built into test.js. I'm trying to connect it in another project:
import test from 'path/test_project/lib/components/test.'

export default {
  name: "my_page",
  data () {
    return {}
  },
  components: {
    test
  }
}

File: .babelrc :
{
  "presets": ,
  "plugins": [
    "transform-export-default"/*,
    "add-module-exports" */
  ]
}

I'm trying to run a project. And I get an error:
"export 'default' (imported as 'test') was not found in 'path/test_project/lib/components/test
'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2018-08-24
@bingo347

try adding to the output section libraryExport: 'default'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question