Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Erro npm run build-dev

Ao executar o comando npm run build-dev recebo o seguinte erro:

> client@1.0.0 build-dev C:\Users\rafae\desenv\alura-webpack\client
> webpack --config webpack.config.js

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules should be an array:
   [object { enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, resource?, resourceQuery?, compiler?, rules?, test?, use? }] 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@1.0.0 build-dev: `webpack --config webpack.config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the client@1.0.0 build-dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\rafae\AppData\Roaming\npm-cache\_logs\2020-08-13T13_26_07_300Z-debug.log

Meu package.json está da seguinte forma:

{
  "name": "client",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build-dev": "webpack --config webpack.config.js",
    "build-prod": "cross-env NODE_ENV=production webpack -p --config webpack.config.js",
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "reflect-metadata": "^0.1.10"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2017": "^6.24.1",
    "babili-webpack-plugin": "^0.1.1",
    "cross-env": "^5.0.1",
    "webpack": "^3.1.0",
    "webpack-dev-server": "^2.5.1"
  }
}

Meu webpack.config.js:

const path = require('path');
const babiliPlugin = require('babili-webpack-plugin');

let plugins = [];
if (process.env.NODE_ENV == 'production') {
  plugins.push(new babiliPlugin());
}

module.exports = {
  entry: path.resolve(__dirname, 'app-src', 'app.js'),
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: {
      test: /\.js$/,
      exclude: /node_modules/,
      use: {
        loader: 'babel-loader',
      },
    },
  },
};
2 respostas
solução!

Boa tarde.

Passei pelo mesmo problema e constatei que em:

 modules: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use : {
                    loader: 'babel-loader'
                }
            }
        ]
    }

modules na realidade e "module", no singular pelo menos resolveu meu problema e passou normal.

Boa sorte !

Muito obrigado!

Que erro besta... hahahaha

Obrigado pela ajuda!