Struggling with Rollbar and TypeScript, their documentation is about as clear as AWS's.
I'm in the process of creating a reusable package based on Rollbar, utilizing the latest TS version (currently 4.2.4).
Let's delve into some code snippets without further delay!
In my index.ts file, I bring in Rollbar like so:
import Rollbar from 'rollbar';
This method is documented by Rollbar themselves.
Few lines down, I simply instantiate the logger using a straightforward new statement:
const options = {
// [...]
}
this._logger = new Rollbar(options);
Coupled with the below tsconfig setup, I manage to successfully build and release the package:
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"rootDir": "src/",
"outDir": "dist/",
"declaration": true,
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"include": ["src/index.ts"]
}
However, there's a hiccup - an error surfaces when trying to utilize the published package that has me perplexed.
TypeError: rollbar_1.default is not a constructor
Upon inspecting the generated JS, it appears the import uses importDefault and assigns the result to rollbar_1.
const rollbar_1 = __importDefault(require("rollbar"));
class Logger {
constructor(options, context) {
const config = {
accessToken: '',
reportLevel: '',
codeVersion: '',
environment: ''
};
this._logger = new rollbar_1.default(config);
}
}
Here I am, stuck without a clue.
The root cause eludes me, and I can't pinpoint the issue at hand.
For those willing to lend a hand, here's the project's tsconfig using the package:
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"outDir": "./dist/",
"rootDir": "./src/"
},
"exclude": ["node_modules", "tests"],
"include": ["src"]
}
And for Sean, here's the outcome of "require('rollbar')":
https://i.stack.imgur.com/T4gnW.png
The output isn't offering much assistance.
I've reached out to Rollbar support for guidance.