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