Javascript 无法在angular 8中使用写入良好的npm模块
我使用的是Angular 8.2.4。我下载的npm模块写得不错。当我尝试在我的测试组件中使用时,我得到了错误引用错误:未定义匹配。 这是组件代码Javascript 无法在angular 8中使用写入良好的npm模块,javascript,angular,typescript,Javascript,Angular,Typescript,我使用的是Angular 8.2.4。我下载的npm模块写得不错。当我尝试在我的测试组件中使用时,我得到了错误引用错误:未定义匹配。 这是组件代码 import { Component, OnInit } from '@angular/core'; import * as writeGood from 'write-good'; @Component({ selector: 'app-textnpm', templateUrl: './textnpm.component.html',
import { Component, OnInit } from '@angular/core';
import * as writeGood from 'write-good';
@Component({
selector: 'app-textnpm',
templateUrl: './textnpm.component.html',
styleUrls: ['./textnpm.component.css']
})
export class TextnpmComponent implements OnInit {
testString: string;
constructor() { }
ngOnInit() {
this.hello();
}
public hello() {
this.testString = writeGood('so so the cat was stolen.');
}
}
下面是错误详细信息
ERROR ReferenceError: match is not defined
at Object.push../node_modules/weasel-words/weasel.js.module.exports [as fn] (weasel.js:40)
at write-good.js:101
at Array.forEach (<anonymous>)
at writeGood (write-good.js:97)
at TextnpmComponent.hello (textnpm.component.ts:18)
at TextnpmComponent.ngOnInit (textnpm.component.ts:14)
at checkAndUpdateDirectiveInline (core.js:31909)
at checkAndUpdateNodeInline (core.js:44366)
at checkAndUpdateNode (core.js:44305)
at debugCheckAndUpdateNode (core.js:45327)
错误引用错误:未定义匹配
在Object.push../node_modules/weasel words/weasel.js.module.exports[as fn](weasel.js:40)
写得好。js:101
在Array.forEach()处
在writeGood(write good.js:97)
在TextnpmComponent.hello(textnpm.component.ts:18)
位于TextnpmComponent.ngonit(textnpm.component.ts:14)
在checkAndUpdateDirectiveInline(core.js:31909)
在checkAndUpdateNodeLine(core.js:44366)
在checkAndUpdateNode(core.js:44305)
在debugCheckAndUpdateNode(core.js:45327)
要获得预期的结果,请使用以下选项,即使用writeGood的默认方法
public hello() {
this.testString = writeGood.default('so so the cat was stolen.');
console.log(this.testString);
}
参考工作守则-
选项2:使用下面的行导入写入良好
导入writeGood=require('write-good')
有关通过导出函数或类而不是模块或对象导入javascript库的更多详细信息,请参阅此链接
同样的错误。即使没有默认方法,它也能在stackblitz上工作。@Waqas,使用选项2和引用链接更新了我的答案。编译时,我得到以下错误------错误TS1202:当目标为ECMAScript模块时,无法使用导入分配。考虑从“mod”、“导入”{a}从“mod”、“导入d”、“mod”或另一个模块格式。