我试图在我的应用程序中使用qrcode-generator但我的设置没有成功,即使它在plunker中工作,在我的应用程序中我使用的是 angular-cli 和 angular 2.rc-1。
重现步骤:
ng new newAppName
cd newAppName
ng serve
那么它的工作原理。
npm i qrcode-generator // (note this is missing the svg support).
ng serve // still work
然后更改2个文件中的配置。角-cli-build.js:
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/**/*.+(js|js.map)',
'rxjs/**/*.+(js|js.map)',
'qrcode-generator/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)'
]
});
};
和系统配置.ts:
/**********************************************************************************
* User Configuration.
*********************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
'qrcode-generator': 'vendor/qrcode-generator'
};
const packages: any = {
'vendor/qrcode-generator': {
main: 'qrcode',
defaultExtension: 'js'
}
};
// ... the rest is the same
像这样编辑new-app-name.component.ts
并导入其中的二维码生成器
// vscode underline the qrcode-generator string and complai about not finding it
import * as qrcode from 'qrcode-generator';
那么ng serve
仍然出现此消息的错误:
/path/to/project/newAppName/tmp/broccoli_type_script_compiler-input_base_path-jscpZEq5.tmp/0/src/app/new-app-name.component.ts (3, 25): 找不到模块 'qrcode-generator'。
我尝试通过将其添加到 typings.json 文件来为其安装类型:
"globalDependencies": {
"qrcode-generator": "registry:dt/qrcode-generator#0.0.0+20160412152159"
}
然后运行:
typings i
安装成功,但还是同样的错误。角-cli版本:
angular-cli: 1.0.0-beta.5
node: 6.2.0
os: linux x64
我错过了什么吗?
我还缺少其他配置吗?