title: STRIPE + TypeScript : TypeError: stripe_1.default is not a constructor
body: <p>I'm running some testings of Stripe code in my TypeScript MicroService :</p>
  <pre><code>process.env.STRIPE_KEY = 'sk_test_...............';
  import Stripe from 'stripe';
  export const stripe = new Stripe(process.env.STRIPE_KEY!, {
    apiVersion: '2020-03-02',
  });
  </code></pre>
  <p>However I keep getting that the constructor is not defined :</p>
  <pre><code> **TypeError: stripe_1.default is not a constructor**
  
   1 | import Stripe from 'stripe';
  &gt; 2 | export const stripe = new Stripe(process.env.STRIPE_KEY!, {
      |                       ^
    3 |   apiVersion: '2020-03-02',
    4 | });
    5 |
  
    at Object.&lt;anonymous&gt; (src/stripe.ts:2:23)
    at Object.&lt;anonymous&gt; (src/routes/new.ts:14:1)
    at Object.&lt;anonymous&gt; (src/app.ts:6:1)
    at Object.&lt;anonymous&gt; (src/routes/__test__/newNoMocks.test.ts:3:1)
   
  </code></pre>
  <p><strong>Package JSON:</strong></p>
  <pre><code>&quot;dependencies&quot;: {    
      &quot;@types/cookie-session&quot;: &quot;^2.0.40&quot;,
      &quot;@types/express&quot;: &quot;^4.17.3&quot;,
      &quot;@types/jsonwebtoken&quot;: &quot;^8.5.0&quot;,
      &quot;@types/mongoose&quot;: &quot;^5.7.22&quot;,
      &quot;cookie-session&quot;: &quot;^1.4.0&quot;,
      &quot;express&quot;: &quot;^4.17.1&quot;,
      &quot;express-async-errors&quot;: &quot;^3.1.1&quot;,
      &quot;express-validator&quot;: &quot;^6.4.0&quot;,
      &quot;jsonwebtoken&quot;: &quot;^8.5.1&quot;,
      &quot;mongoose&quot;: &quot;^5.9.18&quot;,
      &quot;mongoose-update-if-current&quot;: &quot;^1.4.0&quot;,
      &quot;stripe&quot;: &quot;^8.81.0&quot;,
      &quot;ts-node-dev&quot;: &quot;^1.0.0-pre.44&quot;,
      &quot;typescript&quot;: &quot;^3.8.3&quot;
    },
  </code></pre>
  <p>Any idea what might cause this ?</p>
  <p><strong>TSCONFIG:</strong></p>
  <pre><code>{
    &quot;compilerOptions&quot;: {
      /* Basic Options */
      // &quot;incremental&quot;: true,                   /* Enable incremental compilation */
      &quot;target&quot;: &quot;es5&quot;,                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
      &quot;module&quot;: &quot;commonjs&quot;,                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
      // &quot;lib&quot;: [],                             /* Specify library files to be included in the compilation. */
      // &quot;allowJs&quot;: true,                       /* Allow javascript files to be compiled. */
      // &quot;checkJs&quot;: true,                       /* Report errors in .js files. */
      // &quot;jsx&quot;: &quot;preserve&quot;,                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
      &quot;declaration&quot;: true,                   /* Generates corresponding '.d.ts' file. */
      // &quot;declarationMap&quot;: true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */
      // &quot;sourceMap&quot;: true,                     /* Generates corresponding '.map' file. */
      // &quot;outFile&quot;: &quot;./&quot;,                       /* Concatenate and emit output to single file. */
      &quot;outDir&quot;: &quot;./build&quot;,                        /* Redirect output structure to the directory. */
      // &quot;rootDir&quot;: &quot;./&quot;,                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
      // &quot;composite&quot;: true,                     /* Enable project compilation */
      // &quot;tsBuildInfoFile&quot;: &quot;./&quot;,               /* Specify file to store incremental compilation information */
      // &quot;removeComments&quot;: true,                /* Do not emit comments to output. */
      // &quot;noEmit&quot;: true,                        /* Do not emit outputs. */
      // &quot;importHelpers&quot;: true,                 /* Import emit helpers from 'tslib'. */
      // &quot;downlevelIteration&quot;: true,            /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
      // &quot;isolatedModules&quot;: true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
  
      /* Strict Type-Checking Options */
      &quot;strict&quot;: true,                           /* Enable all strict type-checking options. */
      // &quot;noImplicitAny&quot;: true,                 /* Raise error on expressions and declarations with an implied 'any' type. */
      // &quot;strictNullChecks&quot;: true,              /* Enable strict null checks. */
      // &quot;strictFunctionTypes&quot;: true,           /* Enable strict checking of function types. */
      // &quot;strictBindCallApply&quot;: true,           /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
      // &quot;strictPropertyInitialization&quot;: true,  /* Enable strict checking of property initialization in classes. */
      // &quot;noImplicitThis&quot;: true,                /* Raise error on 'this' expressions with an implied 'any' type. */
      // &quot;alwaysStrict&quot;: true,                  /* Parse in strict mode and emit &quot;use strict&quot; for each source file. */
  
      /* Additional Checks */
      // &quot;noUnusedLocals&quot;: true,                /* Report errors on unused locals. */
      // &quot;noUnusedParameters&quot;: true,            /* Report errors on unused parameters. */
      // &quot;noImplicitReturns&quot;: true,             /* Report error when not all code paths in function return a value. */
      // &quot;noFallthroughCasesInSwitch&quot;: true,    /* Report errors for fallthrough cases in switch statement. */
  
      /* Module Resolution Options */
      // &quot;moduleResolution&quot;: &quot;node&quot;,            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
      // &quot;baseUrl&quot;: &quot;./&quot;,                       /* Base directory to resolve non-absolute module names. */
      // &quot;paths&quot;: {},                           /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
      // &quot;rootDirs&quot;: [],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
      // &quot;typeRoots&quot;: [],                       /* List of folders to include type definitions from. */
      // &quot;types&quot;: [],                           /* Type declaration files to be included in compilation. */
      // &quot;allowSyntheticDefaultImports&quot;: true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
      &quot;esModuleInterop&quot;: true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
      // &quot;preserveSymlinks&quot;: true,              /* Do not resolve the real path of symlinks. */
      // &quot;allowUmdGlobalAccess&quot;: true,          /* Allow accessing UMD globals from modules. */
  
      /* Source Map Options */
      // &quot;sourceRoot&quot;: &quot;&quot;,                      /* Specify the location where debugger should locate TypeScript files instead of source locations. */
      // &quot;mapRoot&quot;: &quot;&quot;,                         /* Specify the location where debugger should locate map files instead of generated locations. */
      // &quot;inlineSourceMap&quot;: true,               /* Emit a single file with source maps instead of having a separate file. */
      // &quot;inlineSources&quot;: true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
  
      /* Experimental Options */
      // &quot;experimentalDecorators&quot;: true,        /* Enables experimental support for ES7 decorators. */
      // &quot;emitDecoratorMetadata&quot;: true,         /* Enables experimental support for emitting type metadata for decorators. */
      /* Advanced Options */
      ,&quot;forceConsistentCasingInFileNames&quot;: true /* Disallow inconsistently-cased references to the same file. */
    }
  }
  </code></pre>
  <p><strong>EDIT #2 - 02-08-20 - The Test:</strong></p>
  <p><strong>new.test.ts :</strong></p>
  <pre><code>import mongoose from 'mongoose';
  import request from 'supertest';
  import { app } from '../../app';
  import { Order } from '../../models/order';
  import { OrderStatus } from '@myNPMpackage/common';
  import { stripe } from '../../stripe';
  import { Payment } from '../../models/payment';
  
  it('No Mock - returns a 201 with valid inputs', async () =&gt; {
    const userId = mongoose.Types.ObjectId().toHexString();
    const price = Math.floor(Math.random() * 100000);
    // create order
    const order = Order.build({
      id: mongoose.Types.ObjectId().toHexString(),
      userId,
      version: 0,
      price,
      status: OrderStatus.Created,
    });
  
    await order.save();
  
    // send API Request
    await request(app)
      .post('/api/payments')
      .set('Cookie', global.signin(userId))
      .send({
        orderId: order.id,
        token: 'tok_visa', // valid token
      })
      .expect(201);
  
    const stripeCharges = await stripe.charges.list({ limit: 50 });
    const stripeCharge = stripeCharges.data.find((charge) =&gt; {
      return charge.amount === price * 100; // *100 because we move from Dollars to Cents
    });
    expect(stripeCharge).toBeDefined();
    expect(stripeCharge!.currency).toEqual('usd');
  
    // Test Payment
    const payment = await Payment.findOne({
      orderId: order.id,
      stripeId: stripeCharge!.id,
    });
  
    expect(payment).not.toBeNull();
  });
  </code></pre>
  <p><strong>The Router</strong></p>
  <pre><code>router.post(
    '/api/payments',
    requireAuth,
    [body('token').not().isEmpty(), body('orderId').not().isEmpty()],
    validateRequest,
    async (req: Request, res: Response) =&gt; {
      const { token, orderId } = req.body;
      const order = await Order.findById(orderId);
      if (!order) {
        throw new NotFoundError();
      }
      if (order.userId !== req.currentUser!.id) {
        throw new NotAuthorizedError();
      }
  
      if (order.status === OrderStatus.Cancelled) {
        throw new BadRequestError('Cannot pay for a cancelled order!');
      }
  
      // Call Stripe and charge Credit Cards
      const charge = await stripe.charges.create({
        currency: 'usd',
        amount: order.price * 100, // given in USD , we need to convert to CENTS
        source: token,
      });
  
      // Create a payment
      const payment = Payment.build({
        orderId,
        stripeId: charge.id,
      });
  
      // Save the payment
      await payment.save();
  
      // Call publisher
      await new PaymentCreatedPublisher(natsWrapper.client).publish({
        id: payment.id,
        orderId: payment.orderId,
        stripeId: payment.stripeId,
      });
  
      res.status(201).send(payment);
    }
  );
  </code></pre>
  <p><strong>app.ts :</strong></p>
  <pre><code>import express from 'express';
  import 'express-async-errors';
  import { json } from 'body-parser';
  import cookieSession from 'cookie-session';
  import { errorHandler, NotFoundError, currentUser } from '@myNPMpackage/common';
  import { createChargeRouter } from './routes/new';
  
  const app = express();
  app.set('trust proxy', true); // express is aware that it's behind a proxy inginx and it should trust traffic from that proxy
  app.use(json());
  app.use(
    cookieSession({
      signed: false,
      secure: false, // this one means - don't send cookie if the request is not HTTPS (Secured) , HTTP request won't receive the cookie
      // secure : process.env.NODE_ENV !== 'test'
    })
  );
  
  app.use(currentUser);
  app.use(createChargeRouter);
  
  app.all('*', async (req, res, next) =&gt; {
    // next(new NotFoundError());
    throw new NotFoundError();
  });
  
  app.use(errorHandler);
  
  export { app };
  </code></pre>