最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

AngularTypeScript编译的初学者问题

IT培训 admin 3浏览 0评论

Angular / TypeScript编译的初学者问题

我正在研究“为.NET开发人员学习Angular”一书中的项目。第3章有两个。我对项目代码本身没有问题。问题是我无法让项目运行。在打字稿变换过程中构建失败。

我正在使用npm start命令调用代码。这是package.json文件的脚本部分:

"name": "angular-io-example",
"version": "1.0.0",
"scripts": {
    "test:once": "karma start karma.conf.js --single-run",
    "build": "tsc -p src/",
    "serve": "lite-server -c=bs-config.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "build:watch": "tsc -p src/ -w",
    "build:upgrade": "tsc",
    "serve:upgrade": "http-server",
    "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
    "serve:aot": "lite-server -c bs-config.aot.json",
    "build:babel": "babel src -d src --extensions \".es6\" --source-maps",
    "copy-dist-files": "node ./copy-dist-files.js",
    "i18n": "ng-xi18n",
    "lint": "tslint ./src/**/*.ts -t verbose"
  } 

(不幸的是,这本书没有解释package.json文件 - 它只是将它作为可下载的内容提供给你。)

问题发生在构建命令"build": "tsc -p src/"

当我尝试按原样运行它时,我在命令行界面中获得以下内容:

>tsc -p src/

node_modules/@types/angular/index.d.ts(232,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(233,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1252,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1253,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1972,55): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1976,54): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1986,55): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1991,57): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(2005,48): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(2088,22): error TS1005: ',' expected.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: 'tsc -p src/'
npm ERR! Exit status 2

我不确定node_modules错误是否是问题,因为我可以使用tsc手动编译打字稿代码。我得到相同的错误消息,但代码编译。 (我也很困惑为什么转换器完全引用了node_module代码,因为它在tsconfig.json文件中被设置为“exclude”。)

然而,问题似乎在于tsc命令。我发现,如果我用一些愚蠢的东西替换build命令,比如“ipconfig”,项目运行完美(因为打字稿代码是手动编译的)。

我希望有人可以向我解释为什么构建过程失败了。

回答如下:

This appears to be a known issue.似乎是由npm update -g typescript解决的。

这显然是针对打字稿版本2.3+解决的,尽管仍然是一个悬而未决的问题。既然如此,StackOverflow只能带你到目前为止 - 请参考GitHub问题,如果这个问题仍然存在(并且您的代码或安装没有任何问题),那么请考虑提出自己的问题。

Angular / TypeScript编译的初学者问题

我正在研究“为.NET开发人员学习Angular”一书中的项目。第3章有两个。我对项目代码本身没有问题。问题是我无法让项目运行。在打字稿变换过程中构建失败。

我正在使用npm start命令调用代码。这是package.json文件的脚本部分:

"name": "angular-io-example",
"version": "1.0.0",
"scripts": {
    "test:once": "karma start karma.conf.js --single-run",
    "build": "tsc -p src/",
    "serve": "lite-server -c=bs-config.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "build:watch": "tsc -p src/ -w",
    "build:upgrade": "tsc",
    "serve:upgrade": "http-server",
    "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
    "serve:aot": "lite-server -c bs-config.aot.json",
    "build:babel": "babel src -d src --extensions \".es6\" --source-maps",
    "copy-dist-files": "node ./copy-dist-files.js",
    "i18n": "ng-xi18n",
    "lint": "tslint ./src/**/*.ts -t verbose"
  } 

(不幸的是,这本书没有解释package.json文件 - 它只是将它作为可下载的内容提供给你。)

问题发生在构建命令"build": "tsc -p src/"

当我尝试按原样运行它时,我在命令行界面中获得以下内容:

>tsc -p src/

node_modules/@types/angular/index.d.ts(232,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(233,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1252,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1253,41): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1972,55): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1976,54): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1986,55): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(1991,57): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(2005,48): error TS1005: ',' expected.
node_modules/@types/angular/index.d.ts(2088,22): error TS1005: ',' expected.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: 'tsc -p src/'
npm ERR! Exit status 2

我不确定node_modules错误是否是问题,因为我可以使用tsc手动编译打字稿代码。我得到相同的错误消息,但代码编译。 (我也很困惑为什么转换器完全引用了node_module代码,因为它在tsconfig.json文件中被设置为“exclude”。)

然而,问题似乎在于tsc命令。我发现,如果我用一些愚蠢的东西替换build命令,比如“ipconfig”,项目运行完美(因为打字稿代码是手动编译的)。

我希望有人可以向我解释为什么构建过程失败了。

回答如下:

This appears to be a known issue.似乎是由npm update -g typescript解决的。

这显然是针对打字稿版本2.3+解决的,尽管仍然是一个悬而未决的问题。既然如此,StackOverflow只能带你到目前为止 - 请参考GitHub问题,如果这个问题仍然存在(并且您的代码或安装没有任何问题),那么请考虑提出自己的问题。

发布评论

评论列表 (0)

  1. 暂无评论