【问题标题】:Error using lodash in angular2 [duplicate]在angular2中使用lodash时出错[重复]
【发布时间】:2017-11-05 21:56:48
【问题描述】:

我正在尝试在angular 2.4.0 中使用lodash

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.)

有人可以帮忙吗?

【问题讨论】:

标签: angular lodash angular-cli


【解决方案1】:

需要在@types 下安装lodash。

$ npm install --save lodash

$ npm install --save @types/lodash

然后像这样导入

import * as _ from "lodash";

【讨论】:

  • 试过了,但现在出现了不同的错误
  • @NikhilRadadiya 是什么错误?
  • @sachilaranawaka 更新问题,请检查
  • @RahulSingh 更新问题请检查
猜你喜欢
  • 2016-04-15
  • 2017-06-27
  • 2018-08-05
  • 2017-11-08
  • 1970-01-01
  • 2016-08-04
  • 2017-10-18
  • 2020-02-06
  • 1970-01-01
相关资源
最近更新 更多