在angular2中使用lodash时出错[重复]

Posted

技术标签:

【中文标题】在angular2中使用lodash时出错[重复]【英文标题】:Error using lodash in angular2 [duplicate] 【发布时间】: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.)

有人可以帮忙吗?

【问题讨论】:

试试这个hassantariqblog.wordpress.com/2016/10/15/…,希望对你有帮助 @Dr.Tricker 没有帮助 【参考方案1】:

需要在@types 下安装lodash。

$ npm install --save lodash

$ npm install --save @types/lodash

然后像这样导入

import * as _ from "lodash";

【讨论】:

试过了,但现在出现了不同的错误 @NikhilRadadiya 是什么错误? @sachilaranawaka 更新问题,请检查 @RahulSingh 更新问题请检查

以上是关于在angular2中使用lodash时出错[重复]的主要内容,如果未能解决你的问题,请参考以下文章

无法在计算的 Nuxt 中使用 lodash 进行过滤 [重复]

angular2 lodash 导入失败

在 Angular 2 应用程序中导入 socket.io-client 时出错 [重复]

NPM - 无法从 lodash 库中找到名称“Many”和无法找到命名空间“_”

使用 Angular 2 向 API 发出 POST 请求时出错

Angular2 http响应正文出错