LoginSignup
4
2

More than 3 years have passed since last update.

【React】webpackエラー解決方法"Plugin/Preset files are not allowed to export objects, only functions."

Posted at

発生しているエラー


ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/program/Electron/electron-quick-start/electron_hello/node_modules/babel-preset-es2015/lib/index.js
    at createDescriptor (/Users/program/Electron/electron-quick-start/electron_hello/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/Users/program/Electron/electron-quick-start/electron_hello/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
hain.js:67:36)
    at buildRootChain.next (<anonymous>)
    at loadPrivatePartialConfig (/Users/program/Electron/electron-quick-,,,

解決方法

webpack.config.js
const path = require('path')
const webpack = require('webpack')

const externalPlugins = new webpack.ExternalsPlugin('commonjs', [
    'app',
    'auto-updater',
    'browser-window',
    'content-tracing',
    'dialog',
    'electron',
    'global-shortcut',
    'ipc',
    'menu',
    'menu-item',
    'power-monitor',
    'protocol',
    'tray',
    'remote',
    'web-frame',
    'clipboard',
    'crash-reporter',
    'screen',
    'shell'
])

module.exports = {
    entry: {
        index: path.join(__dirname, 'src', 'index.js')
    },
    output: {
        path: path.join(__dirname, 'out'),
        filename: '[name].js'
    },
    devtool: 'cheap-module-eval-source-map',
    target: 'node',
    module: {
        rules: [
            {
                test: /.js$/,
                loader: 'babel-loader',
                options: {
                    presets: ['es2015', 'react']
                }
            }
        ]
    },
    plugins: [
        externalPlugins
    ]
}

上記ファイルの、presets: ['es2015', 'react']presets: ['@babel/preset-env']に変えるだけ!

最後に

私はこの沼に数時間はまりました、、、

4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2