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

Duvida que ngm me ajudou

Quando coloco npm build-prod ele dá o seguinte erro:

'NODE_ENV' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@1.0.0 build-prod: NODE_ENV=production webpack --config webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the client@1.0.0 build-prod 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\NOTE\AppData\Roaming\npm-cache_logs\2020-12-01T19_48_28_221Z-debug.log

22 respostas

const path = require('path'); const babiliPlugin = require('babili-webpack-plugin'); const extractTextPlugin = require ('extract-text-webpack-plugin'); const optimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const webpack = require('webpack');

let plugins = [];

plugins.push(new extractTextPlugin('styles.css'))

plugins.push(new webpack.ProvidePlugin({ '$': 'jquery/dist/jquery.js', 'jQuery': 'jquery/dist/jquery.js' }));

plugins.push(new webpack.optimize.CommonsChunkPlugin({

name: 'vendor',
filename: 'vendor.bundle.js'

}));

if(process.env.NODE__ENV == 'production') {

plugins.push(new babiliPl());
plugins.push(webpack.optimize.ModuleconcatenationPlugin());

plugins.push(new optimizeCSSAssetsPlugin({
    cssProcessor: require('cssnano'),
    cssProcessorOptions: {
        discardComments: {
            removeAll: true
        }
    },
    canPrint: true
}));

}

module.exports = {

entry: {
    app: './app-src/app.js',
    vendor: ['jquery', 'bootstrap', 'reflect-metadata']
},    
output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: "dist"
},
module: {
    rules: [
        {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
                loader: 'babel-loader'
            }
        },
        { 
            test : /\.css$/,
            use: extractTextPlugin.extract({
                fallback: 'style-loader',
                use: 'css-loader'
            }) 

        },
        { 
            test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, 
            loader: 'url-loader?limit=10000&mimetype=application/font-woff' 
        },
        { 
            test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 
            loader: 'url-loader?limit=10000&mimetype=application/octet-stream'
        },
        { 
            test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 
            loader: 'file-loader' 
        },
        { 
            test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 
            loader: 'url-loader?limit=10000&mimetype=image/svg+xml' 
        }           
    ]
},
plugins

}

0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli 'C:\Program Files\nodejs\node.exe', 1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', 1 verbose cli 'run', 1 verbose cli 'build-prod' 1 verbose cli ] 2 info using npm@6.14.6 3 info using node@v12.18.3 4 verbose run-script [ 'prebuild-prod', 'build-prod', 'postbuild-prod' ] 5 info lifecycle client@1.0.0prebuild-prod: client@1.0.0 6 info lifecycle client@1.0.0build-prod: client@1.0.0 7 verbose lifecycle client@1.0.0build-prod: unsafe-perm in lifecycle true 8 verbose lifecycle client@1.0.0build-prod: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules.bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Java\jdk-13.0.1\bin;C:\Program Files (x86)\Brackets\command;C:\nginx;C:\Program Files\nodejs;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk-15\bin;C:\Ruby26-x64\bin;C:\Users\NOTE\AppData\Roaming\Dashlane\6.1950.0.28527\bin\Firefox_Extension{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\NOTE\AppData\Roaming\Dashlane\6.1950.0.28527\ucrt;C:\Users\NOTE\AppData\Roaming\Dashlane\6.1950.0.28527\bin\Qt;C:\Users\NOTE\AppData\Roaming\Dashlane\6.1950.0.28527\bin\Ssl;C:\Users\NOTE\AppData\Roaming\npm;C:\Program Files\JetBrains\PyCharm 2020.2.3\bin; 9 verbose lifecycle client@1.0.0build-prod: CWD: C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client 10 silly lifecycle client@1.0.0build-prod: Args: [ 10 silly lifecycle '/d /s /c', 10 silly lifecycle 'NODE_ENV=production webpack --config webpack.config.js' 10 silly lifecycle ] 11 silly lifecycle client@1.0.0build-prod: Returned: code: 1 signal: null 12 info lifecycle client@1.0.0build-prod: Failed to exec build-prod script 13 verbose stack Error: client@1.0.0 build-prod: NODE_ENV=production webpack --config webpack.config.js 13 verbose stack Exit status 1 13 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:315:20) 13 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:315:20) 13 verbose stack at maybeClose (internal/child_process.js:1021:16) 13 verbose stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:286:5) 14 verbose pkgid client@1.0.0 15 verbose cwd C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client 16 verbose Windows_NT 6.1.7600 17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "build-prod" 18 verbose node v12.18.3 19 verbose npm v6.14.6 20 error code ELIFECYCLE 21 error errno 1 22 error client@1.0.0 build-prod: NODE_ENV=production webpack --config webpack.config.js 22 error Exit status 1 23 error Failed at the client@1.0.0 build-prod script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]

Fala ai Rubens, tudo bem? O problema é porque o Windows não aceita passar variaveis de ambiente direto no comando, para isso, você pode utilizar a biblioteca cross-env: https://www.npmjs.com/package/cross-env

Ela vai garantir a compatibilidade entre diversos S.Os.

Espero ter ajudado.

Mas a onde eu coloco o { "scripts": { "build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js" } }

??

Fala ai Ruvens, é ai mesmo, cria uma nova chave chamada build dentro de scripts com o comando.

Agora tu rode com npm run build.

Espero ter ajudado.

mas amigao, eu nao tem a pasta scripts na aplicacao.

Fala Rubens, o comando build deve ser criado dentro do package.json na sessão de scripts.

Depois tu roda com npm run build.

Espero ter ajudado.

{ "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": "NODE_ENV=production webpack --config webpack.config.js", "start": "webpack-dev-server", "build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js" },

Continua dando o mesmo erro.

{ "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": "NODE_ENV=production webpack --config webpack.config.js", "start": "webpack-dev-server", "build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js" },

Fala Rubens, me manda o log completo do terminal, desde a o comando executado até a ultima linha de log.

Assim eu consigo dar uma olhada completa no mesmo.

Abraços.

Microsoft Windows [versão 6.1.7600] Copyright (c) 2009 Microsoft Corporation. Todos os direitos reservados.

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack>cd client

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>npm run build

client@1.0.0 build C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client cross-env NODE_ENV=production webpack --config build/webpack.config.js

internal/modules/cjs/loader.js:968 throw err; ^

Error: Cannot find module 'C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\build\webpack.config.js' Require stack:

  • C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js
  • C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\webpack.js at Function.Module.resolveFilename (internal/modules/cjs/loader.js:965:15) at Function.Module.load (internal/modules/cjs/loader.js:841:27) at Module.require (internal/modules/cjs/loader.js:1025:19) at require (internal/modules/cjs/helpers.js:72:18) at requireConfig (C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:97:18) at C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:104:17 at Array.forEach () at module.exports (C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js:102:15) at Object. (C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\webpack.js:155:40) at Module.compile (internal/modules/cjs/loader.js:1137:30) { code: 'MODULENOT_FOUND', requireStack: [ 'C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\convert-argv.js', 'C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client\node_modules\webpack\bin\webpack.js' ] } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@1.0.0 build: cross-env NODE_ENV=production webpack --config build/webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the client@1.0.0 build 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\NOTE\AppData\Roaming\npm-cache_logs\2020-12-04T02_11_42_943Z-debug.log

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>

Fala ai Rubens, o problema está em como você passou o arquivo de configuração do Webpack, repare no comando:

cross-env NODE_ENV=production webpack --config build/webpack.config.js

Você está buscando o arquivo dentro de uma pasta build e depoos webpack.config.js. Acredito que esse arquivo de configuração esteja na raiz do projeto, então o comando ficaria:

cross-env NODE_ENV=production webpack --config ./webpack.config.js

Dessa forma você busca e referencia o arquivo da raiz.

Espero ter ajudado.

Fiz exatamente como vc pediu

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>npm run build-prod

client@1.0.0 build-prod C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client NODE_ENV=production webpack --config webpack.config.js

'NODE_ENV' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@1.0.0 build-prod: NODE_ENV=production webpack --config webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the client@1.0.0 build-prod 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\NOTE\AppData\Roaming\npm-cache_logs\2020-12-04T14_24_09_484Z-debug.log

"scripts": { "test": "echo "Error: no test specified" && exit 1", "build-dev": "webpack --config webpack.config.js", "build-prod": "NODE_ENV=production webpack --config webpack.config.js", "start": "webpack-dev-server", "build": "cross-env NODE_ENV=production webpack --config ./webpack.config.js" },

Fala Rubens, acho que tu removeu o cross-env dos comandos, precisa voltar ele no inicio deles.

Espero ter ajudado.

Mesmo erro.

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>npm install --save-dev cross-env npm WARN client@1.0.0 No repository field. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

  • cross-env@6.0.3 updated 1 package and audited 821 packages in 47.658s

25 packages are looking for funding run npm fund for details

found 13 vulnerabilities (4 low, 6 moderate, 3 high) run npm audit fix to fix them, or npm audit for details

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>npm run build-prod

client@1.0.0 build-prod C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client NODE_ENV=production webpack --config webpack.config.js

'NODE_ENV' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@1.0.0 build-prod: NODE_ENV=production webpack --config webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the client@1.0.0 build-prod 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\NOTE\AppData\Roaming\npm-cache_logs\2020-12-04T20_10_06_913Z-debug.log

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>

Fala Rubens, muito estranho, parece que o comando executado ainda esta sem o cross-env:

client@1.0.0 build-prod C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client NODE_ENV=production webpack --config webpack.config.js

Consegue compartilhar o projeto completo? Assim eu consigo dar uma olhada por aqui e simular o problema.

Pode compartilhar através do Github ou Google Drive (zipado).

Fico no aguardo

Alguem???????/

Fala Rubens, dei uma olhada no projeto, olhando o package.json na parte de scripts:

scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build-dev": "webpack --config webpack.config.js",
    "build-prod": "NODE_ENV=production webpack --config webpack.config.js",
    "start": "webpack-dev-server",
    "build": "cross-env NODE_ENV=production webpack --config ./webpack.config.js"
  },

Faltou você definir o cross-env no build-prod. A ideia é que você precisa adicionar o cross-env em todo comando que seta variavel de ambiente inline (como no build e build-prod onde eles setão a NODE_ENV).

Ficando:

scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build-dev": "webpack --config webpack.config.js",
    "build-prod": "cross-env NODE_ENV=production webpack --config webpack.config.js",
    "start": "webpack-dev-server",
    "build": "cross-env NODE_ENV=production webpack --config ./webpack.config.js"
  },

Espero ter ajudado.

Fiz conforme vc falou.

client@1.0.0 build-prod C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client cross-enNODE_ENV=production webpack --config webpack.config.js

'cross-enNODE_ENV' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@1.0.0 build-prod: cross-enNODE_ENV=production webpack --config webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the client@1.0.0 build-prod 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\NOTE\AppData\Roaming\npm-cache_logs\2020-12-11T15_25_14_997Z-debug.log

C:\Users\NOTE\Downloads\Projeto webpack\projeto-webpack\client>

solução!

Fala ai Rubens, tudo bem? Acho que tu definiu o comando errado:

cross-enNODE_ENV=production webpack --config webpack.config.js

Deveria seria cross-env e ter um espaço entre ele e a declaração da variável, ficando:

cross-env NODE_ENV=production webpack --config webpack.config.js

Espero ter ajudado.

Fala Rubens beleza? Vi que já solucionou sua dúvida mas vim deixar uma sugestão pra ti!

O Windowns é muito limitante na questão de variáveis de ambiente, não sei se você utiliza apenas ele para programar mas caso use, acho que vai te ajudar bastante na sua jornada entender como funcionam e como mexer nessas variáveis (pois pra servidores como NGINX por exemplos você vai precisar alterar 'n' coisas para que funcionem)

Vou deixar 2 links que me ajudaram no início que talvez seja útil :D

https://devcontent.com.br/artigos/windows/o-que-sao-como-alterar-criar-excluir-variaveis-de-ambiente

https://rotinadigital.net/variaveis-de-ambiente-do-windows/

Como o tema é muito extenso, só deixei de dica pq sei o quão chato não dar certo sua aplicação, neste caso pode não ter sido o SO, mas o Windowns vira e mexe da alguma coisinha :D

Obrigado, André.