在angular2中使用lodash时出错

时间:2017-06-05 07:18:31

标签: angular lodash angular-cli

我正在lodash

中使用angular 2.4.0

angular-cli"@angular/cli": "1.0.0-rc.4",

试图像这样导入 import * as _ from 'lodash';

也试过

npm install --save lodash

npm install --save @types/lodash

的package.json

{
  "name": "travelz",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.1.3",
    "@angular/common": "^2.4.0",
    "@angular/compiler": "^2.4.0",
    "@angular/core": "^2.4.0",
    "@angular/forms": "^2.4.0",
    "@angular/http": "^2.4.0",
    "@angular/platform-browser": "^2.4.0",
    "@angular/platform-browser-dynamic": "^2.4.0",
    "@angular/router": "^3.4.0",
    "@types/lodash": "^4.14.37",
    "core-js": "^2.4.1",
    "intl": "^1.2.5",
    "lodash": "^4.16.4",
    "rxjs": "^5.1.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0-rc.4",
    "@angular/compiler-cli": "^2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.0.0"
  }
}

收到这些错误:

C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8599,32): ',' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8602,14): ']' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8602,15): ';' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8605,26): ',' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8605,42): '(' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8605,61): ',' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8605,66): ')' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8607,15): ';' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8607,25): Declaration or statement expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8608,23): ')' expected.)
C:/xampp/htdocs/travelz/node_modules/@types/lodash/index.d.ts (8608,46): '(' expected.)

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

需要在@types下安装lodash。

$ npm install --save lodash

$ npm install --save @types/lodash

然后像这样导入

import * as _ from "lodash";