3
respostas

Erro ao executar o comando ng serve

Após ter criado o projeto e executar o comando ng server, apresenta o seguinte erro no console:

Node packages may not be installed. Try installing with 'yarn'. Could not find the '@angular-devkit/build-angular:dev-server' builder's node package. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! bytebank@0.0.0 start: ng serve npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the bytebank@0.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache_logs\2021-12-15T16_49_18_636Z-debug.log

3 respostas

Pela mensagem, parece que faltou instalar o npm. Tente executar os comandos abaixo no terminal, caso ocorra algum problema tente reinstalar o nodejs.

node -v
npm -v

Estou com o node versão: 14.18 e npm versão: 6.14.15, dei um npm install e ao executar novamente o ng serve, deu a seguinte mensagem de erro:

./nodemodules/@angular/common/fesm2015/common.mjs - Error: Module build failed (from ./nodemodules/@angular-devkit/build-angular/src/babel/webpack-loader.js): Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\aulra\bytebank\node_modules@angular\compiler-cli\node_modules@babel\core' imported from C:\aulra\bytebank\node_modules@angular\compiler-cli\bundles\linker\babel\index.js Did you mean to import @babel/core/lib/index.js? at new NodeError (internal/errors.js:322:7) at legacyMainResolve (internal/modules/esm/resolve.js:245:9) at packageResolve (internal/modules/esm/resolve.js:680:14) at moduleResolve (internal/modules/esm/resolve.js:728:18) at Loader.defaultResolve [as resolve] (internal/modules/esm/resolve.js:842:11) at Loader.resolve (internal/modules/esm/loader.js:89:40) at Loader.getModuleJob (internal/modules/esm/loader.js:242:28) at ModuleWrap. (internal/modules/esm/modulejob.js:76:40) at link (internal/modules/esm/module_job.js:75:36)

./nodemodules/@angular/platform-browser/fesm2015/platform-browser.mjs - Error: Module build failed (from ./nodemodules/@angular-devkit/build-angular/src/babel/webpack-loader.js): Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'C:\aulra\bytebank\node_modules@angular\compiler-cli\node_modules@babel\core' imported from C:\aulra\bytebank\node_modules@angular\compiler-cli\bundles\linker\babel\index.js Did you mean to import @babel/core/lib/index.js? at new NodeError (internal/errors.js:322:7) at legacyMainResolve (internal/modules/esm/resolve.js:245:9) at packageResolve (internal/modules/esm/resolve.js:680:14) at moduleResolve (internal/modules/esm/resolve.js:728:18) at Loader.defaultResolve [as resolve] (internal/modules/esm/resolve.js:842:11) at Loader.resolve (internal/modules/esm/loader.js:89:40) at Loader.getModuleJob (internal/modules/esm/loader.js:242:28) at ModuleWrap. (internal/modules/esm/modulejob.js:76:40) at link (internal/modules/esm/module_job.js:75:36)

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **

× Failed to compile.

Resolvi o problem mencionado, removendo e recriando o projeto