[Vue.js Construa Aplicações Incríveis] NODE_ENV' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes

vue

#1

Estou lendo o livro Vue.js Construa Aplicações Incríveis.

Estou no capítulo 6 tentando executar os testes que fiz, mas estou recebendo este erro

NODE_ENV' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes. 

Vi nesta publicação queria seria necessário adicionar a variável no ambiente do Windows, mas não deu certo.

No momento, meus script estão assim

"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "lint": "eslint --ext .js,.vue src test/unit/specs",
    "build": "node build/build.js",
    "unit": "NODE_ENV=testing karma start test/unit/karma.conf.js --single-run",
    "test": "NODE_ENV=testing npm run unit"
  },

Segue o link do repositório do meu projeto https://github.com/iagofrota/todo-list


#2

Olá Iago, bom dia.

Confesso que estou sem Windows para testar, você tentou alterar seu package.json para alterar o NODE_ENV diretamente nas tasks?

"unit": "SET \"NODE_ENV= testing\" && karma start test/unit/karma.conf.js --single-run""

Outra opção seria:

"unit": "SET  NODE_ENV= testing && karma start test/unit/karma.conf.js --single-run""

Poderia me confirmar se funcionou?


#3

Desde já agradeço por ter respondido. Apareceu um resultado melhor:

PS C:\Users\iagof\source\repos\todo-list> npm test

> todo-list@1.0.0 test C:\Users\iagof\source\repos\todo-list
> npm run unit


> todo-list@1.0.0 unit C:\Users\iagof\source\repos\todo-list
> SET "NODE_ENV= testing" && karma start test/unit/karma.conf.js --single-run

12 12 2017 16:17:57.090:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
12 12 2017 16:17:57.097:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
12 12 2017 16:17:57.284:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
12 12 2017 16:17:57.285:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
12 12 2017 16:17:57.335:INFO [launcher]: Starting browser PhantomJS
12 12 2017 16:18:08.209:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#63clhfCiAKtiJJc-AAAA with id 29859739

PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)


=============================== Coverage summary ===============================
Statements   : 100% ( 0/0 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 0/0 )
================================================================================
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-list@1.0.0 unit: `SET "NODE_ENV= testing" && karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-list@1.0.0 unit 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\iagof\AppData\Roaming\npm-cache\_logs\2017-12-12T19_18_08_641Z-debug.log
npm ERR! Test failed.  See above for more details.

Tentei a opção "unit": "SET \"NODE_ENV= testing\" && karma start test/unit/karma.conf.js --single-run" e apaguei do comando test o NODE_ENV= testing. No final, meu script ficou assim

"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "lint": "eslint --ext .js,.vue src test/unit/specs",
    "build": "node build/build.js",
    "unit": "SET \"NODE_ENV= testing\" && karma start test/unit/karma.conf.js --single-run",
    "test": "npm run unit"
  },

#4

Você vai enfrentar bastantes problemas com bash no Windows, uma dica é instalar o Git Bash e tentar rodar através dele.

https://git-for-windows.github.io

Você tentou essa opção?

SET NODE_ENV= testing && karma start test/unit/karma.conf.js --single-run"


#5
PS C:\Users\iagof\source\repos\todo-list> npm test

> todo-list@1.0.0 test C:\Users\iagof\source\repos\todo-list
> npm run unit


> todo-list@1.0.0 unit C:\Users\iagof\source\repos\todo-list
> SET NODE_ENV= testing && karma start test/unit/karma.conf.js --single-run

12 12 2017 16:40:03.977:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
12 12 2017 16:40:03.982:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
12 12 2017 16:40:04.148:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
12 12 2017 16:40:04.149:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
12 12 2017 16:40:04.191:INFO [launcher]: Starting browser PhantomJS
12 12 2017 16:40:12.922:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#-B38CthEbwhJ7UJsAAAA with id 15184048

PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)


=============================== Coverage summary ===============================
Statements   : 100% ( 0/0 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 0/0 )
================================================================================
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-list@1.0.0 unit: `SET NODE_ENV= testing && karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-list@1.0.0 unit 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\iagof\AppData\Roaming\npm-cache\_logs\2017-12-12T19_40_13_455Z-debug.log
npm ERR! Test failed.  See above for more details.

#6

Tentei executar pelo Git Bash, mas estou recebendo a mesma mensagem

iagof@DESKTOP-RNAT4PO MINGW64 ~/source/repos/todo-list (master)
$ npm test

> todo-list@1.0.0 test C:\Users\iagof\source\repos\todo-list
> npm run unit


> todo-list@1.0.0 unit C:\Users\iagof\source\repos\todo-list
> SET NODE_ENV= testing && karma start test/unit/karma.conf.js --single-run

12 12 2017 16:42:45.651:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
12 12 2017 16:42:45.656:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
12 12 2017 16:42:45.717:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
12 12 2017 16:42:45.717:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
12 12 2017 16:42:45.722:INFO [launcher]: Starting browser PhantomJS
12 12 2017 16:42:52.555:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#v6PbwM3obsahoxAEAAAA with id 757701

PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)


=============================== Coverage summary ===============================
Statements   : 100% ( 0/0 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 0/0 )
================================================================================
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-list@1.0.0 unit: `SET NODE_ENV= testing && karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-list@1.0.0 unit 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\iagof\AppData\Roaming\npm-cache\_logs\2017-12-12T19_42_52_726Z-debug.log
npm ERR! Test failed.  See above for more details.

#7

Pelo gitbash deveria funcionar sem precisar fazer o set do node env.


#8

Notei que quando testo desse jeito

"scripts": {
    "dev": "node build/dev-server.js",
    "build": "node build/build.js",
    "lint": "eslint --ext .js,.vue src",
    "unit": "NODE_ENV=testing karma start test/unit/karma.conf.js --single-run",
    "test": "NODE_ENV=testing npm run unit"
  },

Dá esse problemas

iagof@DESKTOP-RNAT4PO MINGW64 ~/source/repos/todo-list (master)
$ npm test

> todo-list@1.0.0 test C:\Users\iagof\source\repos\todo-list
> NODE_ENV=testing npm run unit

'NODE_ENV' n▒o ▒ reconhecido como um comando interno
ou externo, um programa oper▒vel ou um arquivo em lotes.
npm ERR! Test failed.  See above for more details.

E quando testo desse jeito

"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "lint": "eslint --ext .js,.vue src test/unit/specs",
    "build": "node build/build.js",
    "unit":"SET NODE_ENV=testing && karma start test/unit/karma.conf.js --single-run",
    "test": "npm run unit"
  },

Recebo isso

iagof@DESKTOP-RNAT4PO MINGW64 ~/source/repos/todo-list (master)
$ npm test

> todo-list@1.0.0 test C:\Users\iagof\source\repos\todo-list
> npm run unit


> todo-list@1.0.0 unit C:\Users\iagof\source\repos\todo-list
> SET NODE_ENV=testing && karma start test/unit/karma.conf.js --single-run

13 12 2017 16:11:37.640:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
13 12 2017 16:11:37.643:WARN [watcher]: Pattern "C:/Users/iagof/source/repos/todo-list/test/unit/index.js" does not match any file.
13 12 2017 16:11:37.690:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
13 12 2017 16:11:37.691:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
13 12 2017 16:11:37.697:INFO [launcher]: Starting browser PhantomJS
13 12 2017 16:11:46.110:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#RJXR9rdzSYvauD6eAAAA with id 53969919

PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)


=============================== Coverage summary ===============================
Statements   : 100% ( 0/0 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 0/0 )
Lines        : 100% ( 0/0 )
================================================================================
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-list@1.0.0 unit: `SET NODE_ENV=testing && karma start test/unit/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-list@1.0.0 unit 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\iagof\AppData\Roaming\npm-cache\_logs\2017-12-13T19_11_46_460Z-debug.log
npm ERR! Test failed.  See above for more details.

#9

Pode parecer besteira, mas tenta rodar sem espaços:

SET NODE_ENV=testing&& karma start test/unit/karma.conf.js --single-run

se não rolar:

SET NODE_ENV=testing&&karma start test/unit/karma.conf.js --single-run

#10

Isso no terminal padrão do Windows.


#11

Mesmo erro. Apaguei o projeto e dei clone novamente do projeto. Apareceu vários erros para eu instalar alguns pacotes. Parei nessa mensagem:

C:\Users\iagof\Source\Repos\todo-list [master ≡ +0 ~2 -0 !]
λ  npm start

> todo-list@1.0.0 start C:\Users\iagof\Source\Repos\todo-list
> npm run dev


> todo-list@1.0.0 dev C:\Users\iagof\Source\Repos\todo-list
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

C:\Users\iagof\Source\Repos\todo-list\build\webpack.dev.conf.js:44
    new webpack.NoEmitOnErrorsPlugin(),
    ^

TypeError: webpack.NoEmitOnErrorsPlugin is not a constructor
    at Object.<anonymous> (C:\Users\iagof\Source\Repos\todo-list\build\webpack.dev.conf.js:44:5)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at requireConfig (C:\Users\iagof\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:97:18)
    at C:\Users\iagof\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:104:17
    at Array.forEach (<anonymous>)
    at module.exports (C:\Users\iagof\AppData\Roaming\npm\node_modules\webpack\bin\convert-argv.js:102:15)
    at Object.<anonymous> (C:\Users\iagof\AppData\Roaming\npm\node_modules\webpack-dev-server\bin\webpack-dev-server.js:222:50)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-list@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-list@1.0.0 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\iagof\AppData\Roaming\npm-cache\_logs\2017-12-19T00_22_52_430Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-list@1.0.0 start: `npm run dev`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-list@1.0.0 start 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\iagof\AppData\Roaming\npm-cache\_logs\2017-12-19T00_22_52_599Z-debug.log

#12

Referente ao problema anterior, que só ocorre no Windows, recomendo a instalação do cross-env, aparentemente ele normaliza o set de váriavies por ambiente:

npm install cross-env --save

Após isso, os scripts ficariam:

"scripts": {
    "dev": "node build/dev-server.js",
    "build": "node build/build.js",
    "lint": "eslint --ext .js,.vue src",
    "unit": "cross-env NODE_ENV=testing karma start test/unit/karma.conf.js --single-run",
    "test": "cross-env NODE_ENV=testing npm run unit"
  }

#13

Reescrevi o projeto no VueJS 2.5, usando o cross-env:

Precisa tirar um tempo para atualizar o livro.


#14

A solução foi

  1. Atualizar o Vue.js com o comando npm install --global vue-cli
  2. Criar outro projeto com o comando vue init webpack my-project
  3. Copiar a pasta src do projeto para antigo e sobrescrever no novo projeto

Acredita-se que o problema seria algumas incompatibilidades com o Windows, no meu caso Windows 10 PRO.

De qualquer forma, fico muito grato pela a ajuda Caio. Outra coisa, estou adorando o livro!