How to import 'into-stream' package?



const express = require('express');
const app = express();
const cors = require('cors');
const mongoose = require('mongoose');
const multer = require('multer');
const inMemoryStorage = multer.memoryStorage();
const uploadStrategy = multer({ storage: inMemoryStorage }).single('image');
const { BlockBlobClient } = require('@azure/storage-blob');
const getStream = require('into-stream');

I can’t use require in importing ‘into-stream’ module, it gives me ESM error:

Error [ERR_REQUIRE_ESM]: require() of ES Module

I tried adding type:module in package.json however require will not work if I do that. Do I install another version of into-stream? or should I use import rather than require. I am using node.js.


The package doesn’t support require() anymore, just like node-fetch mentioned at this thread:

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported

You should add type: "module" to your package.json and then use:

import getStream from "into-stream";

I suggest you put that in the top of your file, just for code style 😡

If this doesn’t work, downgrade to version 6.0.0, which works with require(), according to the docs:

Answered By – Lucas Henrique

Answer Checked By – Robin (AngularFixing Admin)

Leave a Reply

Your email address will not be published.