angular-cli在ng init和ng build上抛出错误但不是新的错误

时间:2016-07-29 11:18:41

标签: angular angular-cli

我正在尝试在5分钟快速启动应用的修改版本上运行ng build --prod。该项目不是用ng创建的。当我运行ng build --prodng init --source-dir app时,我得到以下错误(我在某处读到的应该有助于构建部分)。我可以成功运行其他ng命令,build命令适用于我使用ng创建的项目。我猜我的项目设置或文件中的某些内容不太正确,但我不明白这个错误消息试图告诉我的内容。另外,我手动更新了从RC2到RC4版本的依赖项,删除了node_modules并运行npm install(不确定这是否重要)。我运行ng new TestApp并手动将angular-cli.jsonangular-cli-build.json文件复制到此项目中,并另外从根文件夹运行npm install angular-cli以查看是否也有帮助,它没有'吨。我也在全球安装了angular-cli。

C:\ng2\testApp\Web.UI.Angular2>ng init --source-dir app
(node:10640) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
C:\ng2\testApp\Web.UI.Angular2\node_modules\angular-cli\node_modules\ember-cli\lib\models\project.js:642
      throw reason;
      ^
SyntaxError: Unexpected token  in JSON at position 0
    at Object.parse (native)
    at Function.Project.closestSync (C:\ng2\testApp\Web.UI.Angular2\node_modules\angular-cli\node_modules\ember-cli\lib\models\project.js:610:16)
    at Function.Project.projectOrnullProject (C:\ng2\testApp\Web.UI.Angular2\node_modules\angular-cli\node_modules\ember-cli\lib\models\project.js:637:20)
    at module.exports (C:\ng2\testApp\Web.UI.Angular2\node_modules\angular-cli\node_modules\ember-cli\lib\cli\index.js:94:25)
    at module.exports (C:\ng2\testApp\Web.UI.Angular2\node_modules\angular-cli\lib\cli\index.js:106:10)
    at C:\Users\Luke.Baughan\AppData\Roaming\npm\node_modules\angular-cli\bin\ng:31:5
    at C:\Users\Luke.Baughan\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:44:21
    at ondir (C:\Users\Luke.Baughan\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:187:31)
    at C:\Users\Luke.Baughan\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:153:39
    at onex (C:\Users\Luke.Baughan\AppData\Roaming\npm\node_modules\angular-cli\node_modules\resolve\lib\async.js:93:22)

System.config.js:

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
    // map tells the System loader where to look for things
    var map = {
        'app': 'app', // 'dist',
        '@angular': 'node_modules/@angular',
        'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
        'rxjs': 'node_modules/rxjs'
    };
    // packages tells the System loader how to load when no filename and/or no extension
    var packages = {
        'app': { main: 'main.js', defaultExtension: 'js' },
        'rxjs': { defaultExtension: 'js' },
        'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
    };
    var ngPackageNames = [
      'common',
      'compiler',
      'core',
      'forms',
      'http',
      'platform-browser',
      'platform-browser-dynamic',
      'router',
      'router-deprecated',
      'upgrade',
    ];
    // Individual files (~300 requests):
    function packIndex(pkgName) {
        packages['@angular/' + pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    // Bundled (~40 requests):
    function packUmd(pkgName) {
        packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }
    // Most environments should use UMD; some (Karma) need the individual index files
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    // Add package entries for angular packages
    ngPackageNames.forEach(setPackageConfig);
    var config = {
        map: map,
        packages: packages
    };
    System.config(config);
})(this);

tsconfig.js:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  }
}

的package.json:

{
  "name": "angular2-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.4",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12",
    "angular2-in-memory-web-api": "0.0.14",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings":"^1.0.4"
  }
}

角cli.json:

{
  "project": {
    "version": "1.0.0-beta.9",
    "name": "testApp"
  },
  "apps": [
    {
      "main": "app/main.ts",
      "tsconfig": "tsconfig.json",
      "mobile": false
    }
  ],
  "addons": [],
  "packages": [],
  "defaults": {
    "prefix": "app",
    "sourceDir": "",
    "styleExt": "css",
    "prefixInterfaces": false,
    "lazyRoutePrefix": "+"
  }
}

角-CLI-build.json:

// Angular-CLI build configuration
// This file lists all the node_modules files that will be used in a build
// Also see https://github.com/angular/angular-cli/wiki/3rd-party-libs

/* global require, module */

var Angular2App = require('angular-cli/lib/broccoli/angular2-app');

module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/**/*.+(js|js.map)',
      'es6-shim/es6-shim.js',
      'reflect-metadata/**/*.+(ts|js|js.map)',
      'rxjs/**/*.+(js|js.map)',
      '@angular/**/*.+(js|js.map)'
    ]
  });
};

所以我的问题是我错过了什么和/或试图告诉我为什么ng build和ng init没有按预期运行的错误是什么。

1 个答案:

答案 0 :(得分:1)

好的,不是最好的,但这就是我的目的:

  • 使用ng new MyApp
  • 创建一个全新的应用
  • 将与我的应用相关的所有位n bobs复制到新项目结构中
  • 运行ng build
  • 运行ng serve

谢天谢地angular-cli非常宽容,我只有一些组件和一些服务,因此移动它并不是太麻烦。