TypeScript Object.defineProperty(exports....... Gumming up the works

So, it has been a very long time since I have coded (feel off the face of the earth doing conservation work in Madagascar since 2013 with occasional gulps up for air / internet), and many things have changed. I did code during that time, there is very little my trusty brackets editor and I could not accomplish while coding by candle light in my hut, but now that I am back in part of the world with internet, it is time to get back up to date with a great many things including modern code styles & environments! So your going to continue to get slammed with a few noob questions for the next few days while I continue to get back up to speed.

Right now I am trying to get my toes wet with typescript using VSCode and followed the NPM guide. Unfortunately I keep getting:

“use strict”;
Object.defineProperty(exports, “__esModule”, { value: true });

written at the top of my converted js files.

I must not have something set up right as I keep getting a console error preventing things from loading.

The exact console error in FF/Chrome is:
ReferenceError: exports is not defined

This happens to each one of my js files converted from ts files.

If I delete those header lines things work fine, but obviously they exist for a reason. Where should exports be declared and how do I fix the definition issue?

This is more a Typescript related issue: Object.defineProperty(exports ...) is emitted even when exports is not defined · Issue #15685 · microsoft/TypeScript · GitHub

Basically as you are (I guess) using commonjs as a typescript target the line is in, you should try to use a different target for TS.

1 Like