我正在使用 Angular2 开发应用程序。我正在尝试导入和使用外部库“benchmark.js”。所以,我使用“npm i --save benchmark”安装它。package.json 的依赖如下。
"name": "angular2-webpack",
"version": "1.0.0",
"description": "A webpack starter for Angular",
"scripts": {
"start": "webpack-dev-server --inline --progress --port 8080",
"test": "karma start",
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"
},
"license": "MIT",
"dependencies": {
"@angular/common": "~2.3.0",
"@angular/compiler": "~2.3.0",
"@angular/core": "~2.3.0",
"@angular/forms": "~2.3.0",
"@angular/http": "~2.3.0",
"@angular/platform-browser": "~2.3.0",
"@angular/platform-browser-dynamic": "~2.3.0",
"@angular/router": "~3.3.0",
"benchmark": "^2.1.3",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-rc.4",
"systemjs": "0.19.40",
"zone.js": "^0.7.2"
},
然后,我运行“npm install”,如果我查看 node_modules,就会发现有 benchmark 目录。但是,当我尝试使用 'import Suite from 'benchmark'' 导入时,它给了我类似'Cannot Fine module'benchmark'之类的错误。我想我可以从 rxjs 导入像 Observable 这样的 Suite 对象。我应用了与 Observable 完全相同的方式。无论如何,我如何能够在我的组件中使用 benchmark.js。