我已经在https://github.com/garg10may/TourOfHeroes
上构建了Angular示例《英雄之旅》应用程序现在,当我尝试克隆它并执行ng serve
时,它给我一个错误
serve命令需要在Angular项目中运行,但是 找不到项目定义。
据我了解,我没有提交angular.json
文件,因此它无法识别相同文件。如何生成相同的内容?
编辑:
如果我使用另一个新项目中的angular.json文件,则会出现错误。
Could not find module "@angular-devkit/build-angular" from "/home/garg10may/TourOfHeroes".
Error: Could not find module "@angular-devkit/build-angular" from "/home/garg10may/TourOfHeroes".
at Object.resolve (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:151:11)
at WorkspaceNodeModulesArchitectHost.resolveBuilder (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:31:40)
at ServeCommand.initialize (/usr/local/lib/node_modules/@angular/cli/models/architect-command.js:135:55)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
尝试安装相同的内容:
garg10may@GCES15511:~/TourOfHeroes$ npm i @angular-devkit/build-angular --save-dev [24/1952]npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@babel/types
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/assert
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/babel-code-frame
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@babel/generator
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@babel/traverse
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/babel-generator
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/body-parser
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/express
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/handlebars
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/del/node_modules/globby
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/del
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/engine.io
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/engine.io-client
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@angular-devkit/build-optimizer
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@angular/compiler-cli
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/codelyzer
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@babel
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/engine.io-client/node_modules
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/engine.io/node_modules
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@angular/compiler-cli/node_modules
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/babel-code-frame/node_modules
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@angular-devkit
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/del/node_modules
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@angular
npm WARN checkPermissions Missing write access to /home/garg10may/TourOfHeroes/node_modules/@types
npm ERR! path /home/garg10may/TourOfHeroes/node_modules/@babel/types
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/home/garg10may/TourOfHeroes/node_modules/@babel/types'
npm ERR! { [Error: EACCES: permission denied, access '/home/garg10may/TourOfHeroes/node_modules/@babel/types']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/home/garg10may/TourOfHeroes/node_modules/@babel/types\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/home/garg10may/TourOfHeroes/node_modules/@babel/types' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/garg10may/.npm/_logs/2019-06-07T06_33_30_442Z-debug.log
garg10may@GCES15511:~/TourOfHeroes$
garg10may@GCES15511:~/TourOfHeroes$
garg10may@GCES15511:~/TourOfHeroes$ sudo npm i @angular-devkit/build-angular --save-dev
npm ERR! path /home/garg10may/TourOfHeroes/node_modules/@babel/highlight
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rename
npm ERR! Error: EACCES: permission denied, rename '/home/garg10may/TourOfHeroes/node_modules/@babel/highlight' -> '/home/garg10may/TourOfHeroes/node_modules/@babel/.highlight.DELETE'
npm ERR! { [Error: EACCES: permission denied, rename '/home/garg10may/TourOfHeroes/node_modules/@babel/highlight' -> '/home/garg10may/TourOfHeroes/node_modules/@babel/.highlight.DELETE']
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, rename '/home/garg10may/TourOfHeroes/node_modules/@babel/highlight' -> '/home/garg10may/TourOfHeroes/node_modules/@babel/.highlight.DELETE'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/home/garg10may/TourOfHeroes/node_modules/@babel/highlight',
npm ERR! dest:
npm ERR! '/home/garg10may/TourOfHeroes/node_modules/@babel/.highlight.DELETE' },
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, rename \'/home/garg10may/TourOfHeroes/node_modules/@babel/highlight\' -> \'/home/garg10may/TourOfHeroes/node_modules/@babel/.highlight.DELETE\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/home/garg10may/TourOfHeroes/node_modules/@babel/highlight',
npm ERR! dest:
npm ERR! '/home/garg10may/TourOfHeroes/node_modules/@babel/.highlight.DELETE',
npm ERR! parent: 'angular-tour-of-heroes' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/garg10may/.npm/_logs/2019-06-07T06_35_12_613Z-debug.log
答案 0 :(得分:2)
您还需要从新项目中复制tsconfig.app.json
和angular.json
这些文件。
现在运行
npm update
-> npm install
-> ng serve
请记住以 sudo 的身份运行所有命令。
答案 1 :(得分:1)
进行了一次测试。使用ng new
创建了一个新项目,并添加了所有丢失的文件(不仅是angular.json)。该项目运行良好。您的问题可能与此重复:Angular6: How can I generate a default angular.json file from command line