Search code examples
typescriptmongoose-sequence

What does "can only be default-imported using the 'esModuleInterop' flag" mean?


I am getting the following error:

lib/app.ts:1:8 - error TS1259: Module '"mongoose-sequence"' can only be default-imported using the 'esModuleInterop' flag

on the following line of code:

import _ from 'mongoose-sequence';

Now, I'm happy to admit I'm missing something with the whole "underscore as a function name" thing, but the error makes no sense, as the esModuleInterop flag is absolutely, positively set to true in my ts.config file.

I am trying to import this:

declare module 'mongoose-sequence' {
  import mongoose = require('mongoose');
  var _: (schema: mongoose.Schema, options?: Object) => void;
  export = _;

from the mongoose-sequence DefinitelyTyped definition.

What am I missing?


Solution

  • Try with: import _ = require('mongoose-sequence');

    https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require