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?
The error "Module can only be default-imported using esModuleInterop flag" occurs when we try to import a CommonJS module into an ES6 module. To solve the error, set the esModuleInterop option to true in your tsconfig. json file.
We highly recommend applying it both to new and existing projects. esModuleInterop is also a recommended option to set in tsconfig. json and when one runs tsc --init it gets set to true automatically.
esModuleInterop. Enable TypeScript emitted code to work with code emitted by the Babel ecosystem. This flag is introduced in TypeScript 2.7. Prior to 2.7, when importing commonjs module, you have to do either import x = require('x') or import * as x from 'x' .
Try with: import _ = require('mongoose-sequence');
https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With