Hi. I have an issue with using an npm module that ...
# typescript
g
Hi. I have an issue with using an npm module that contains code of my dynamic provider (let’s call it
my-provider
). I add it as a dependency in my pulumi program using git url (so I have
"my-provider": "git+ssh……"
in my pulumi program package.json). Now when I try to run
pulumi up
I’m getting:
TypeError: Class constructor Resource cannot be invoked without 'new'
. Both my provider module and my pulumi program tsconfig.json is the following:
Copy code
{
  "compilerOptions": {
    "strict": true,
    "outDir": "bin",
    "target": "es2016",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "experimentalDecorators": true,
    "pretty": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "forceConsistentCasingInFileNames": true
  },
  "files": [
    "index.ts"
  ]
}
Any hints what I might be doing wrong?
l
How are you importing the provider and instantiating it?
g
@little-cartoon-10569 Like this:
Copy code
import {MyResource} from 'my-module/myprovider';

;; ...

const myResource = new MyResource(..., ...);
l
You're invoking it with a
new
, so the error message makes no sense to me. Are you exporting a default?
g
This is how I define my resource class in the module:
Copy code
export class MyResource extends pulumi.dynamic.Resource {
    constructor(name: string, args: ...) {
         super(myProvider, name, args);
    }
}
What I found on the net is that this issue might occur when a class compiled to ES6 is extended by code that is then compiled to ES5. But I have es2016 in the target in tsconfig.json in both - the module and the pulumi program
When I look at the js sources compiled from ts sources, in my case it’s actually the opposite: the code creating MyResource instance in the pulumi program uses new MyResource, but in the module transpiled from ts to js, it does
_super.call(…)
instead of
new Resource
.