npm命令中的模块构建失败

时间:2019-01-07 03:31:16

标签: node.js reactjs npm webpack babel

我在命令下跑了

npm run dev

我的 package.json 文件如下所示。

{
  "name": "fulljs",
  "version": "1.0.0",
  "description": "fulljs",
  "main": "index.js",
  "scripts": {
    "start": "nodemon --exec babel-node server.js --ignore public/",
    "dev": "webpack -wd"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@babel/core": "^7.2.2",
    "ejs": "^2.6.1",
    "express": "^4.14.0",
    "mongodb": "^3.1.10",
    "react": "^16.7.0",
    "react-dom": "^16.7.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.5",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "eslint": "^5.12.0",
    "eslint-plugin-react": "^7.12.3",
    "nodemon": "^1.18.9",
    "webpack": "^2.1.0-beta.22",
    "webpack-cli": "^3.2.0"
  }
}

我的 webpack.config.js 文件如下所示

module.exports = {
    entry: './src/index.js',
    output: {
        path: __dirname + '/public',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel-loader'
            }
        ]
    }
};

我遇到错误了

foysal@laptop:~/Videos/fulljs$ npm run dev

> fulljs@1.0.0 dev /home/foysal/Videos/fulljs
> webpack -wd


Webpack is watching the files…

Hash: 540477b12d4127d3ac17
Version: webpack 2.1.0-beta.22
Time: 161ms
    Asset     Size  Chunks             Chunk Names
bundle.js  5.08 kB       0  [emitted]  main
    + 1 hidden modules

ERROR in ./src/index.js
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In /home/foysal/Videos/fulljs/node_modules/babel-preset-react/lib/index.js
    at createDescriptor (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/config-chain.js:120:22)
    at loadPrivatePartialConfig (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/partial.js:85:55)
    at Object.loadPartialConfig (/home/foysal/Videos/fulljs/node_modules/@babel/core/lib/config/partial.js:110:18)
    at Object.<anonymous> (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:140:26)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:3:103)
    at _next (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:5:194)
    at /home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:5:364
    at new Promise (<anonymous>)
    at Object.<anonymous> (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:5:97)
    at Object._loader (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:220:18)
    at Object.loader (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:56:18)
    at Object.<anonymous> (/home/foysal/Videos/fulljs/node_modules/babel-loader/lib/index.js:51:12)

我的 .babelrc 文件如下所示

{
  "presets": ["react", "es2015", "stage-2","babel/env","babel/react"]
}

0 个答案:

没有答案