我正在尝试在angular2项目中导入crypto-js.
我跟着几个SO问题和angular-cli guide,但最后我仍然有错误找不到模块’crypto-js’
我尝试了什么:
npm install crypto-js –save
和
typings安装dt~crypto-js –global –save
var Angular2App = require('angular-cli/lib/broccoli/angular2-app'); module.exports = function(defaults) { return new Angular2App(defaults,{ vendorNpmFiles: [ 'systemjs/dist/system-polyfills.js','systemjs/dist/system.src.js','zone.js/dist/**/*.+(js|js.map)','es6-shim/es6-shim.js','reflect-Metadata/**/*.+(ts|js|js.map)','rxjs/**/*.+(js|js.map)','@angular/**/*.+(js|js.map)','crypto-js/**/*.+(js|js.map)' ] }); };
和文件src / system-config.ts
const map: any = { 'crypto-js': 'vendor/crypto-js' }; /** User packages configuration. */ const packages: any = { 'crypto-js': { format: 'cjs' } };
使用后
从’crypto-js’导入*作为CryptoJS;
我还有错误.我错过了什么 ?
谢谢
解决方法
这可能对您有所帮助:
https://github.com/Uisli21/SecureAngularLogin
https://github.com/Uisli21/SecureAngularLogin
$npm install crypto-js --save $npm install @types/crypto-js --save-dev
然后:
import * as CryptoJS from 'crypto-js';
要么
import CryptoJS = require('crypto-js');