鍍金池/ 問答/HTML/ webpack打包問題

webpack打包問題

$ webpack
Hash: 1f773e86011e3cb1394a
Version: webpack 3.8.1
Time: 239ms
    Asset     Size  Chunks             Chunk Names
bundle.js  4.44 kB       0  [emitted]  main
   [0] ./app/index.js 1.97 kB {0} [built] [failed] [1 error]

ERROR in ./app/index.js
Module build failed: Error: [BABEL] /home/ubuntu/workspace/electron/electron-quick-start/app/index.js: Plugin/Preset files are not allowed to export objects, only functions.
    at createDescriptor (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/option-manager.js:365:11)
    at /home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/option-manager.js:188:12
    at Array.map (<anonymous>)
    at /home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/option-manager.js:187:48
    at cachedFunction (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/caching.js:48:17)
    at OptionManager.mergeOptions (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/option-manager.js:53:18)
    at OptionManager.init (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/option-manager.js:121:14)
    at manageOptions (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/option-manager.js:37:30)
    at loadConfig (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/config/index.js:15:37)
    at Object.transform (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_@babel_core@7.0.0-beta.31@@babel/core/lib/transform.js:13:36)
    at transpile (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_babel-loader@8.0.0-beta.0@babel-loader/lib/index.js:55:20)
    at Object.module.exports (/home/ubuntu/workspace/electron/electron-quick-start/node_modules/_babel-loader@8.0.0-beta.0@babel-loader/lib/index.js:179:20)

使用webpack打包時出現(xiàn)的一個問題,請各位幫忙看看,以下是配置文件

webpack配置 webpack.config.js

const path = require('path');

const config = {
  entry: './app/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['env', 'react']
          }
        }
      },
      {
        test: /\.less$/,
        use: [
          {
            loader: "style-loader"
          }, {
            loader: "css-loader"
          }, {
            loader: "less-loader"
          }
        ]
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      }
    ]
  },
  node: {
    fs: "empty"
  }
};

module.exports = config;

入口文件index.js

import React from 'react'
import ReactDOM from 'react-dom'
import Main from './js/Main'

ReactDOM.render(<Main />, document.getElementById('app'))
回答
編輯回答
傻叼

你用的是 測試版本的BABEL 包嗎

2018年9月19日 07:59
編輯回答
老梗

已經(jīng)解決, 重新加載模塊之后沒問題了。index.js是沒問題的

2017年4月13日 08:10
編輯回答
何蘇葉

錯誤不是已經(jīng)告訴你了
/home/ubuntu/workspace/electron/electron-quick-start/app/index.js: Plugin/Preset files are not allowed to export objects, only functions.

index.js文件的export不允許對象只能是函數(shù)

2018年3月7日 19:01