2
respostas

npm run build-dev não funciona após a instalação do babel-loader

Após a instalação do babel-loader, quando eu tento executar o npm run build-dev (aproximadamente no minuto 6:25 da aula "11 Babel-loader, a ponte entre o Webpack e o Babel") acontece o seguinte erro:

> webpack --config webpack.config.js

C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:507
                                throw new Error("'output.filename' is required, either in config file or as --output-filename");
                                ^

Error: 'output.filename' is required, either in config file or as --output-filename
    at processOptions (C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:507:11)
    at processConfiguredOptions (C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:150:4)
    at module.exports (C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:112:10)
    at yargs.parse (C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\webpack\bin\webpack.js:171:41)    
    at Object.Yargs.self.parse (C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\yargs\yargs.js:533:18)    at Object.<anonymous> (C:\Users\allan.santos\Documents\Projetos Angular\01-projeto-webpack\projeto-webpack\client\node_modules\webpack\bin\webpack.js:152:7)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
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.

Alguém consegue ajudar? Obrigado

2 respostas

Pelo erro: Error: 'output.filename' is required, either in config file or as --output-filename da execução Eu testei aqui, e provavelmente na pasta webpack.config.js dentro do escopo de output, você não declarou o filename

// ...
output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    }
// ...

Se ajudou, marca como solucionado!

Muito obrigado pela resposta mas infelizmente não é isso, o erro persiste. Vou colocar os outros arquivos:

Arquivo webpack.config.js:

const path = require('path');
module.export = {
  entry: './app-src/app.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
},
  module: {
    rules:[
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader : 'babel-loader'
        }
      }
    ]
  }
}

Arquivo package.json

{
  "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"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "reflect-metadata": "^0.1.10"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.5",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-preset-es2017": "^6.24.1",
    "webpack": "^3.1.0"
  }
}

Arquivo .babelrc

{
    "presets":["es2017"],
    "plugins" : ["transform-decorators-legacy"]
}

Obrigado!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software