admin管理员组文章数量:1225000
I am getting an error when trying to import a default class from an external node_module and I cannot resolve any help appreciated
[external module]
path : node_module/@123-grp-node/node-000/src/abc-xxxx.ts
[abc-xxxx.ts]
export default class Apple{
getCredentials(){
...
}
}
[abcService.js]
import Apple from '@123-grp-node/node-000';
const app = new Apple(); <----- Error
app.getCredentials();
My issue is when using the new keyword I am getting the error 'Apple is not a constructor'
I know this error is generated when trying to use the new keyword on something that is not a constructor but class 'abc-xxxx.ts' has no defined constructor so per my understanding the default constructor should be used.
A little background this dependency was previously working using require I am trying to use import instead.
[old - working ]
const Apple = require('@123-grp-node/node-000');
const app = new Apple.default();
[new - not working]
import Apple from '@123-grp-node/node-000';
const app = new Apple();
I also want to note that the external module is being found as I am able to control click on the getCredential method and jump to correct file.
[tsconfig.json]
{
"compilerOptions":{
"target":"es6",
"module":"commonjs",
"experimentalDecorators":true,
"emitDecoratorMetadata":true,
"outDir": "dist",
"noImplicitAny":false,
"noImplicitReturns":true,
"strictNullChecks": true,
"esModuleInterop": true,
"declaration":true,
"sourceMap": true,
"lib":[
"es2015",
"es6",
"es7",
"dom"
],
"include":[
"src/test/**/*.ts"
"src/**/*.ts"
],
"exclude":[
"node_modules"
]
}
本文标签: typescriptGetting error when importing default class in JavascriptStack Overflow
版权声明:本文标题:typescript - Getting error when importing default class in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739447549a2163536.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论