我有一个“引证-js”包,它使用commonJS风格的导入。
为了在角中使用它,我安装了@type/ node,然后在tsconfig.app.json中的类型数组中添加了节点
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": ["node"],
"resolveJsonModule": true
},
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.d.ts"]
}我开始测试app.component.ts中的包
ngOnInit() {
let example = new Cite("Q21972834");
let output = example.format("bibliography", {
format: "html",
template: "apa",
lang: "en-US",
});
console.log(output);
}运行之后,我仍然会遇到一个错误
ERROR in ./node_modules/@citation-js/plugin-ris/lib-mjs/spec/mixed.js
Module not found: Error: Can't resolve './additions' in '/home/inkant/citationjs/node_modules/@citation-js/plugin-ris/lib-mjs/spec'所以我调查了这个包裹
import ADDITIONS from './additions';我注意到“./ and”是JSON file而不是JS module。现在我能做些什么来使用这个包.
在我看来,这似乎是CommonJS和ES6模块之间的不同之处.
发布于 2020-04-28 00:48:35
我找到了直接将JSON导入类型记录的方法。请将建议的两个更改添加到tsconfig.json / tsconfig.app.json文件中:
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true
}然而,引文-js包是用Browserify开发的,不喜欢类型记录编译器。它和Webpack打得不好,而Webpack是角球的默认绑定器。因此,要使用它的角度:
在组件上,我再次使用了window.require,而不是导入或普通的需求,因为我不希望类型记录试图编译引文-js。我在citation.js的顶部看到它包含了一个需求的实现,这可能是一个浏览器化工件。因此,底线是禁用类型记录编译,将其包含在资产中。
https://stackoverflow.com/questions/61460560
复制相似问题