cmd 上的错误“ng serve”

Posted

技术标签:

【中文标题】cmd 上的错误“ng serve”【英文标题】:Error "ng serve" on cmd 【发布时间】:2017-06-26 07:23:11 【问题描述】:

当我在 cmd "ng serve" 键入运行 angular2 时,出现错误:

"未知浏览器查询 basedir=$(dirname $(echo $0 | sed -es,\,/,g))"

未知浏览器查询basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") BrowserslistError:未知浏览器查询basedir=$(dirname "$(echo "$0" | sed - e 's,\\,/,g')") 出错时(D:\angular_node\aaa\node_modules\browserslist\index.js:37:11) 在 D:\angular_node\aaa\node_modules\browserslist\index.js:215:9 在 Array.forEach (本机) 在 browserslist (D:\angular_node\aaa\node_modules\browserslist\index.js:192: 13) 在 cleanBrowsersList (D:\angular_node\aaa\node_modules\caniuse-api\dist\util s.js:56:59) 在 setBrowserScope (D:\angular_node\aaa\node_modules\caniuse-api\dist\index. js:30:43) 在对象。 (D:\angular_node\aaa\node_modules\caniuse-api\dist\ind ex.js:92:1) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\postcss-merge-rules\ dist\lib\ensureCompatibility.js:7:19) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\postcss-merge-rules\ dist\index.js:23:28) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\cssnano\dist\index.j 年代:113:26) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\angular-cli\models\w ebpack-configs\styles.js:6:15) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\angular-cli\models\w ebpack-configs\index.js:8:10) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\angular-cli\models\w ebpack-config.js:4:25) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\angular-cli\tasks\se rve.js:11:24) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在对象。 (D:\angular_node\aaa\node_modules\angular-cli\commands \serve.run.js:6:15) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) 在需要(内部/module.js:20:19) 在 Class.run (D:\angular_node\aaa\node_modules\angular-cli\commands\serve.js :67:16) 在课堂上。 (D:\angular_node\aaa\node_modules\angular-cli\ember-cli \lib\models\command.js:134:17) 在 process._tickCallback (internal/process/next_tick.js:103:7)

所以我在 Google Globe 中搜索了所有内容,但一无所获。 谁能告诉我怎么解决???不管怎么说,还是要谢谢你... 注意:我在 Windows 8 32 位上运行

Angular-cli.json


  "project": 
    "version": "1.0.0-beta.28.3",
    "name": "testing"
  ,
  "apps": [
    
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [],
      "environments": 
        "source": "environments/environment.ts",
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      
    
  ],
  "e2e": 
    "protractor": 
      "config": "./protractor.conf.js"
    
  ,
  "lint": [
    
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    ,
    
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    
  ],
  "test": 
    "karma": 
      "config": "./karma.conf.js"
    
  ,
  "defaults": 
    "styleExt": "css",
    "prefixInterfaces": false,
    "inline": 
      "style": false,
      "template": false
    ,
    "spec": 
      "class": false,
      "component": true,
      "directive": true,
      "module": false,
      "pipe": true,
      "service": true
    
  

package.json


  "name": "testing",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": ,
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  ,
  "private": true,
  "dependencies": 
    "@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "^3.3.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  ,
  "devDependencies": 
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.28.3",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "~4.0.13",
    "ts-node": "1.2.1",
    "tslint": "^4.3.0",
    "typescript": "~2.0.3"
  

【问题讨论】:

给我看看你的 package.jsonangular-cli.json 文件。 我已将其添加到我的问题中 【参考方案1】:

我在节点版本 10.0.0 和 angular cli 版本 1.7.4 的 Windows 10 上遇到了同样的问题。现在删除了项目目录中的 browserlists 文件和 browserslist.cmd。它对我有用:)。

【讨论】:

【参考方案2】:

只需从项目目录中删除“browserlist”(文本文件),同时删除“browserlist.cmd”文件。 (它对我有用)

【讨论】:

【参考方案3】:

见: https://github.com/angular/angular-cli/issues/3938#issuecomment-272633128

(将项目文件夹中的文件名“browserlist”更改为“00_browserslist”,已为我修复)

【讨论】:

以上是关于cmd 上的错误“ng serve”的主要内容,如果未能解决你的问题,请参考以下文章

仅当 ng serve --prod 时出现 AngularFire 错误

Angular 8 - ng build prod 在 ng serve 工作时显示错误 - 模块导入的意外值“未定义”

我有一个新项目,但是执行 ng serve 时出现错误

Angular 10 运行 ng serve 获取 webpack,内存错误

在angular2应用程序中运行ng serve时出现错误'无法读取未定义的属性'长度''

ng serve 不会编译