【问题标题】:Angular 2 npm start issueAngular 2 npm 启动问题
【发布时间】:2017-12-17 18:28:56
【问题描述】:

当我尝试运行命令 npm start 时,会出现如下错误:

我的 package.json 文件是:-

{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
    "build": "tsc -p src/",
    "build:prod": "webpack -p --progress",
    "build:watch": "tsc -p src/ -w",
    "build:e2e": "tsc -p e2e/",
    "serve": "lite-server -c=bs-config.json",
    "serve:e2e": "lite-server -c=bs-config.e2e.json",
    "prestart": "npm run build",
    "start": "concurrently \"nodemon server/main.js\" \"npm run build:watch\" \"npm run serve\"",
    "pree2e": "npm run build:e2e",
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
    "preprotractor": "webdriver-manager update",
    "protractor": "protractor protractor.config.js",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "postinstall": "typings install",
    "test:once": "karma start karma.conf.js --single-run",
    "lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
    "@agm/core": "^1.0.0-beta.0",
    "@angular/animations": "^4.2.5",
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/core": "~4.0.0",
    "@angular/forms": "~4.0.0",
    "@angular/http": "~4.0.0",
    "@angular/material": "^2.0.0-beta.7",
    "@angular/platform-browser": "~4.0.0",
    "@angular/platform-browser-dynamic": "~4.0.0",
    "@angular/router": "~4.0.0",
    "@ngui/map": "^0.18.3",
    "@types/googlemaps": "^3.26.14",
    "angular-in-memory-web-api": "~0.3.0",
    "angular2-image-upload": "^0.6.3",
    "angular2-modal": "^3.0.1",
    "angular2-useful-swiper": "^4.0.5",
    "auth0-js": "^8.7.0",
    "core-js": "^2.4.1",
    "cors": "^2.8.3",
    "debug-log": "^1.0.1",
    "express": "^4.14.0",
    "font-awesome": "^4.6.3",
    "hammerjs": "^2.0.8",
    "http-server": "^0.10.0",
    "jquery": "^2.2.4",
    "mysql": "^2.13.0",
    "ng": "0.0.0-rc6",
    "ng2-float-btn": "0.0.3",
    "ng2-page-scroll": "^4.0.0-beta.9",
    "ng2-parallax": "^1.0.0",
    "ngx-flickity": "0.0.6",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.8.4"
},
"devDependencies": {
    "concurrently": "^3.2.0",
    "lite-server": "^2.2.2",
    "typescript": "~2.1.0",
    "typings": "^1.3.2",
    "webpack": "^1.13.2",
    "canonical-path": "0.0.2",
    "tslint": "^3.15.1",
    "lodash": "^4.16.4",
    "jasmine-core": "~2.4.1",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~4.0.14",
    "rimraf": "^2.5.4",
    "@types/node": "^6.0.46",
    "@types/jasmine": "2.5.36"
},
"repository": {}
}

我的 tsconfig.json 文件是:-

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

请告诉我我需要更改什么以及如何在服务器上部署项目?

【问题讨论】:

  • 你需要定义参数,我猜你正在运行 aot 构建,它期望函数的类型,你需要提供相同的类型
  • 请告诉我如何定义参数类型? @RahulSingh
  • 如果你看到错误声明,你会看到 value 有隐含类型 any 使它成为你传递的每一个值,从 value: any 到 value : //你的类型字符串或数字或用户定义的类型
  • 如果我的值是字符串,那我该怎么办?请给我一个例子(语法)@RahulSingh
  • value:string 应该可以为所有反映错误的函数指定这样的技巧

标签: angular npm package.json


【解决方案1】:

您可以简单地添加:

"noImplicitAny": "false"

到您的tsconfig.json 中的compilerOptions,它应该可以解决此问题。

【讨论】:

  • 这已经是 false,但仍然会出现这样的错误。
  • @keyz.Mist 你介意分享 tsconfig 文件吗?
  • 请检查 tsconfig 文件中的问题。 @Chrillewoodz
【解决方案2】:

在我的情况下,我做到了

In package.json file
When I "npm start" the application didn't run, then I changed it to
"start": "concurrently "npm run tsc:w" "npm run lite" ", in package.json
then the application ran without errors.

希望对你有帮助

【讨论】:

  • 不,这不是问题。
猜你喜欢
  • 1970-01-01
  • 2018-01-11
  • 2019-11-29
  • 2020-07-09
  • 2020-03-19
  • 2016-10-26
  • 1970-01-01
  • 2020-12-23
  • 1970-01-01
相关资源
最近更新 更多