angular-cli 在 ng init 和 ng build 上抛出错误,但在 ng new 上抛出错误
angular-cli throws error on ng init and ng build but not ng new
我正在尝试 运行 ng build --prod
5 分钟快速启动应用程序的修改版本。该项目不是用 ng 创建的。当我 运行 ng build --prod
或 ng init --source-dir app
时出现以下错误(我在某处读到的应该有助于构建部分)。我可以 运行 其他 ng 命令成功,并且构建命令适用于我使用 ng 创建的项目。我猜我的项目设置或文件中有些地方不太正确,但我不明白此错误消息试图告诉我什么。此外,我手动将依赖项从 RC2 更新到 RC4 版本,删除了 node_modules 和 运行 npm install
(不确定这是否重要)。我 运行 ng new TestApp
并手动将 angular-cli.json
和 angular-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"
}
}
angular-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": "+"
}
}
angular-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)'
]
});
};
所以我的问题是我错过了什么 and/or 试图告诉我为什么 ng build 和 ng init 没有按预期 运行 的错误是什么。
好吧,这不是最好的,但这就是我的选择:
- 使用
ng new MyApp
创建一个全新的应用
- 将与我的应用程序相关的所有内容复制到新项目结构中
- 运行
ng build
- 运行
ng serve
谢天谢地 angular-cli
非常宽容,我只有几个组件和一些服务,所以移动它并不太麻烦。
我正在尝试 运行 ng build --prod
5 分钟快速启动应用程序的修改版本。该项目不是用 ng 创建的。当我 运行 ng build --prod
或 ng init --source-dir app
时出现以下错误(我在某处读到的应该有助于构建部分)。我可以 运行 其他 ng 命令成功,并且构建命令适用于我使用 ng 创建的项目。我猜我的项目设置或文件中有些地方不太正确,但我不明白此错误消息试图告诉我什么。此外,我手动将依赖项从 RC2 更新到 RC4 版本,删除了 node_modules 和 运行 npm install
(不确定这是否重要)。我 运行 ng new TestApp
并手动将 angular-cli.json
和 angular-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"
}
}
angular-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": "+"
}
}
angular-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)'
]
});
};
所以我的问题是我错过了什么 and/or 试图告诉我为什么 ng build 和 ng init 没有按预期 运行 的错误是什么。
好吧,这不是最好的,但这就是我的选择:
- 使用
ng new MyApp
创建一个全新的应用 - 将与我的应用程序相关的所有内容复制到新项目结构中
- 运行
ng build
- 运行
ng serve
谢天谢地 angular-cli
非常宽容,我只有几个组件和一些服务,所以移动它并不太麻烦。