ng服务失败,找不到本地工作空间文件('angular.json')。角度5

时间:2018-06-24 22:34:26

标签: angular npm angular-cli

首先我在正确的目录中

我尝试ng服役于今天的早期儿童,但现在出现以下错误:

Local workspace file ('angular.json') could not be found.
Error: Local workspace file ('angular.json') could not be found.
    at WorkspaceLoader._getProjectWorkspaceFilePath (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/workspace-loader.js:37:19)
    at WorkspaceLoader.loadWorkspace (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/workspace-loader.js:24:21)
    at ServeCommand._loadWorkspaceAndArchitect (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/architect-command.js:180:32)
    at ServeCommand.<anonymous> (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/architect-command.js:47:25)
    at next (native)
    at /home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/architect-command.js:7:71
    at __awaiter (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/architect-command.js:3:12)
    at ServeCommand.initialize (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/architect-command.js:46:16)
    at Object.<anonymous> (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/models/command-runner.js:87:23)
    at next (native)

然后我跑了ng update @angluar/cli --migrate-only --from 1.7.4

我是通过遵循此堆栈溢出帖子中的第一个答案来做到这一点的:Error: Local workspace file ('angular.json') could not be found

更新中的错误:

Error compiling schema, function code: var customRule0 = customRules[0]; var validate = async function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict';  var vErrors = null;  var errors = 0;      if (rootData === undefined) rootData = data;  if ((data && typeof data === "object" && !Array.isArray(data))) {   if (data.force === undefined) data.force =  false ;   if (data.all === undefined) data.all =  false ;   if (data.next === undefined) data.next =  false ;   if (data.migrateOnly === undefined) data.migrateOnly =  false ;   var errs__0 = errors;var valid1 = true; var data1 = data.packages;  if ( data1 === undefined ) { valid1 = true; } else {   var errs_1 = errors; if (Array.isArray(data1)) {   var errs__1 = errors;var valid1;  for (var i1 = 0; i1 < data1.length; i1++) {   var errs_2 = errors; if (typeof data1[i1] !== "string") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.packages[' + i1 + ']' , schemaPath: '#/properties/packages/items/type' , params: { type: 'string' }  , message: 'should be string'  } ]);  }    var valid2 = errors === errs_2;  if (!valid2) break;  }    }  else {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.packages' , schemaPath: '#/properties/packages/type' , params: { type: 'array' }  , message: 'should be array'  } ]);  }  if (errors === errs_1) {   customRule0.errors = null;var errs__1 = errors;var valid1; var customErrors1 = null; try { valid1 = await   customRule0.call( self , data1  , (dataPath || '') + '.packages' , data , 'packages' , rootData )  ; } catch (e) { valid1 = false; if (e instanceof ValidationError) customErrors1 = e.errors; else throw e; }  if (data) data1 = data['packages']; if (  !valid1) {  if (Array.isArray(customErrors1)) { if (vErrors === null) vErrors = customErrors1; else vErrors = vErrors.concat(customErrors1); errors = vErrors.length;  for (var i1=errs__1; i1<errors; i1++) { var ruleErr1 = vErrors[i1]; if (ruleErr1.dataPath === undefined) ruleErr1.dataPath = (dataPath || '') + '.packages';  ruleErr1.schemaPath = "#/properties/packages/$default";   } } else {  throw new ValidationError([ { keyword: '$default' , dataPath: (dataPath || '') + '.packages' , schemaPath: '#/properties/packages/$default' , params: { keyword: '$default' }  , message: 'should pass "$default" keyword validation'  } ]);  }  }    }  var valid1 = errors === errs_1; }  if (valid1) {   var errs_1 = errors; if (typeof data.force !== "boolean") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.force' , schemaPath: '#/properties/force/type' , params: { type: 'boolean' }  , message: 'should be boolean'  } ]);  }    var valid1 = errors === errs_1;  if (valid1) {   var errs_1 = errors; if (typeof data.all !== "boolean") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.all' , schemaPath: '#/properties/all/type' , params: { type: 'boolean' }  , message: 'should be boolean'  } ]);  }    var valid1 = errors === errs_1;  if (valid1) {   var errs_1 = errors; if (typeof data.next !== "boolean") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.next' , schemaPath: '#/properties/next/type' , params: { type: 'boolean' }  , message: 'should be boolean'  } ]);  }    var valid1 = errors === errs_1;  if (valid1) {   var errs_1 = errors; if (typeof data.migrateOnly !== "boolean") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.migrateOnly' , schemaPath: '#/properties/migrateOnly/type' , params: { type: 'boolean' }  , message: 'should be boolean'  } ]);  }    var valid1 = errors === errs_1;  if (valid1) {  if ( data.from === undefined ) { valid1 = true; } else {   var errs_1 = errors; if (typeof data.from !== "string") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.from' , schemaPath: '#/properties/from/type' , params: { type: 'string' }  , message: 'should be string'  } ]);  }    var valid1 = errors === errs_1; }  if (valid1) {  if ( data.to === undefined ) { valid1 = true; } else {   var errs_1 = errors; if (typeof data.to !== "string") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.to' , schemaPath: '#/properties/to/type' , params: { type: 'string' }  , message: 'should be string'  } ]);  }    var valid1 = errors === errs_1; }  if (valid1) {  var data1 = data.registry;  if ( data1 === undefined ) { valid1 = true; } else {   var errs_1 = errors; if (typeof data1 !== "string") {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + '.registry' , schemaPath: '#/properties/registry/type' , params: { type: 'string' }  , message: 'should be string'  } ]);  }   var errs__1 = errors , prevValid1 = false , valid1 = false , passingSchemas1 = null;    var errs_2 = errors;   if (errors === errs_2) {  if (typeof data1 === "string") {    if (!  formats.uri.test(data1) ) {  var err =  { keyword: 'format' , dataPath: (dataPath || '') + '.registry' , schemaPath: '#/properties/registry/oneOf/0/format' , params: { format:  'uri'  }  , message: 'should match format "uri"'  } ;  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++;  }    }  }  var valid2 = errors === errs_2;  if (valid2) { valid1 = prevValid1 = true; passingSchemas1 = 0; }   var errs_2 = errors;   if (errors === errs_2) {  if (typeof data1 === "string") {    if (!  formats.hostname.test(data1) ) {  var err =  { keyword: 'format' , dataPath: (dataPath || '') + '.registry' , schemaPath: '#/properties/registry/oneOf/1/format' , params: { format:  'hostname'  }  , message: 'should match format "hostname"'  } ;  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++;  }    }  }  var valid2 = errors === errs_2;  if (valid2 && prevValid1) { valid1 = false; passingSchemas1 = [passingSchemas1, 1]; } else {  if (valid2) { valid1 = prevValid1 = true; passingSchemas1 = 1; }}if (!valid1) {   var err =    { keyword: 'oneOf' , dataPath: (dataPath || '') + '.registry' , schemaPath: '#/properties/registry/oneOf' , params: { passingSchemas: passingSchemas1 }  , message: 'should match exactly one schema in oneOf'  } ;  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++;  throw new ValidationError(vErrors); } else {  errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; }  }    var valid1 = errors === errs_1; }  }}}}}}}   }  else {  throw new ValidationError([ { keyword: 'type' , dataPath: (dataPath || '') + "" , schemaPath: '#/type' , params: { type: 'object' }  , message: 'should be object'  } ]);  }    if (errors === 0) return data;            else throw new ValidationError(vErrors);  }; return validate;

我不知道该如何解决这个问题。

更新:

我删除了package-lock.json,然后运行npm install,然后尝试ng serve,然后遇到了与以前相同的错误,即我的配置已更改并且必须运行ng update。

运行ng并得到与上面相同的错误。

尝试了此修复程序:

npm install --save-dev @angular/cli@v6.0.0-rc.4
ng update @angular/cli --migrate-only --from=1.7.4

然后出现此错误:

/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:79
  async run(environment) {
        ^^^
SyntaxError: Unexpected identifier
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at module.exports (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/ember-cli/lib/cli/index.js:17:15)
    at default_1 (/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/frontend/suitsandtables/node_modules/@angular/cli/lib/cli/index.js:37:12)

3 个答案:

答案 0 :(得分:2)

它对我有用

ng update @angular/cli

答案 1 :(得分:0)

我遇到了同样的问题,您可以尝试以下方法:

npm install -g angular-universal-pwa@beta
ng new --collection angular-universal-pwa myAwesomeApp
cd myAwesomeApp
npm start

答案 2 :(得分:0)

提问者说

  

首先我在正确的目录中

...那是我的问题。

您应该在角度目录中运行ng test
如果您的项目有多个目录,请在运行测试之前确保进入正确的目录。