【问题标题】:Angular 2+, How to generate angular.json manuallyAngular 2+,如何手动生成 angular.json
【发布时间】:2019-06-07 16:04:38
【问题描述】:

我在 https://github.com/garg10may/TourOfHeroes 上构建了 Angular 示例 Tour of Heroes 应用程序

现在当我尝试克隆它并执行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

【问题讨论】:

  • 从 Angular CLI 生成新项目并复制 angular.json 文件...我认为这应该可以工作
  • npm i @angular-devkit/build-angular --save-dev
  • 本教程应该足以让您入门。事实上,这个问题是无法回答的。
  • 如果 devkit 的 npm install 没有帮助,重启 IDE。还要检查 build-angular 套件的版本。有一些已知问题。由于两个项目的大合并,最近几天也出现了这个错误。
  • 如果没有您的文件结构和您运行的命令(以及您运行它的位置),我们无法回答您。请提供minimal reproducible example

标签: angular


【解决方案1】:

您还需要tsconfig.app.jsonangular.json 从新项目中复制这些文件。

现在运行

npm update --> npm install --> ng serve

记得以 sudo 运行所有命令。

【讨论】:

  • 它抛出了 babel 的权限被拒绝错误,发布在问题中
  • @garg10您是否正在更新您的 Angular 应用版本?
  • 是的,使用 sudo 命令,全局角度为 8,应用程序角度为 7
  • @angular-devkit/build-angular 这是在 Angular 6 中引入的。
  • 好的,我再次检查了需要添加angular.jsontsconfig.json 的项目都丢失了。 Ran npm update --> npm install --> ng serve 这次没有报错。我认为npm update 是解决这一切的关键。谢谢你的建议。
【解决方案2】:

刚刚做了一个测试。使用ng new 创建了一个新项目,并添加了所有丢失的文件(不仅是 angular.json)。该项目运行良好。您的问题可能与此重复:Angular6: How can I generate a default angular.json file from command line

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 2019-09-10
    • 2017-08-15
    • 2023-03-24
    • 2018-01-18
    • 1970-01-01
    相关资源
    最近更新 更多