export 'default' was not found when I try to import my webpack library

Viewed 1264

This is my source code ./source/client/main.jsx.

export default {
  test: () => console.log('Flow')
};

And this is my webpack.config.cjs.

const path = require('path');
const webpack = require('webpack');
const packageJSON = require('./package.json');

module.exports = (env, argv) => {
  return {
    mode: 'development',
    entry: './source/client/main.jsx',
    // entry: './main.js',
    output: {
      path: path.join(__dirname, 'release'),
      filename: 'main.js',
      library: {
        name: packageJSON.name,
        type: 'umd'
      }
    },
    devtool: 'source-map',
    module: {
      rules: [
        {
          test: /\.jsx?$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
            options: {
              presets: [
                '@babel/preset-env',
                '@babel/preset-react'
              ],
              plugins: [
                '@babel/plugin-transform-runtime'
              ]
            }
          }
        }
      ]
    }
  };
};

My package.json contains a list of dependencies and both main and module pointing to the webpack product.

  "main": "./release/main.js",
  "module": "./release/main.js",

However, when I try to import my module in another webpack project, I get the default was not found error.

import Test from 'test';
export 'default' (imported as 'Test') was not found in 'test' (module has no exports)

Am I building the module wrong?

0 Answers
Related