'Application unable to work due to rate limiter

I have tried to implement rate limiter on server.js but it gives this error below making the website crash. Did I implement the rate limiter wrongly? I have tried changing the rate and apiLimiter line position but it didnt work. Below server.js is the error log. As this is the first time I encounter this error log issue, I am not sure where to look for the issue. This is my first time implementing rate limiter in server.js so please advice.

Application error
An error occurred in the application and your page could not be served

server.js

import express from 'express'
import path from 'path'
import mongoose from 'mongoose'
import cors from 'cors'
import rateLimit from 'express-rate-limiter'
import config from './config'
import userRoute from './routes/userRoute'
import uploadRoute from './routes/uploadRoute'
import productRoute from './routes/productRoute'
import orderRoute from './routes/orderRoute'

const mongodbUrl = config.MONGODB_URL;
mongoose.connect(mongodbUrl, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useCreateIndex: true,
  }).catch((error) => console.log(error.reason))

const app = express()

const apiLimiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100
})

app.use(cors())
app.use(express.json())
app.use('/api/', apiLimiter)
app.use('/api/users', userRoute)
app.use('/api/uploads', uploadRoute)
app.use('/api/products', productRoute)
app.use('/api/orders', orderRoute)
app.get('/api/paypal/clientId', (req, res) => {
  res.send({ clientId: config.PAYPAL_CLIENT_ID })
})

app.use('/uploads', express.static(path.join(__dirname, '/../uploads')))
app.use(express.static(path.join(__dirname, '/../frontend')))
app.get('*', (req, res) => {
  res.sendFile(path.join(`${__dirname}/../frontend/index.html`)) 
})

// eslint-disable-next-line no-unused-vars
app.use((err, req, res, next) => {
  const status = err.name && err.name === 'ValidationError' ? 400 : 500
  res.status(status)
  res.send({ message: err.message })
})

2021-05-29T05:11:02.707267+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T05:11:02.707268+00:00 app[web.1]: ^
2021-05-29T05:11:02.707268+00:00 app[web.1]: 
2021-05-29T05:11:02.707269+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function
2021-05-29T05:11:02.707269+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T05:11:02.707270+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:49)
2021-05-29T05:11:02.707270+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T05:11:02.707270+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T05:11:02.707271+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T05:11:02.707271+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)   
2021-05-29T05:11:02.707272+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) 
2021-05-29T05:11:02.707272+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T05:11:02.778624+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T05:11:02.853093+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T05:11:59.000000+00:00 app[api]: Build started by user [email protected]
2021-05-29T05:13:01.344269+00:00 app[api]: Deploy c8670dff by user [email protected]
2021-05-29T05:13:01.344269+00:00 app[api]: Release v88 created by user [email protected]
2021-05-29T05:13:02.041520+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T05:13:03.000000+00:00 app[api]: Build succeeded
2021-05-29T05:13:06.356963+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-05-29T05:13:10.148201+00:00 app[web.1]: /app/node_modules/express-rate-limiter/index.js:13
2021-05-29T05:13:10.148263+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T05:13:10.148272+00:00 app[web.1]: ^
2021-05-29T05:13:10.148276+00:00 app[web.1]: 
2021-05-29T05:13:10.148276+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function
2021-05-29T05:13:10.148279+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T05:13:10.148279+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:49)
2021-05-29T05:13:10.148280+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T05:13:10.148280+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T05:13:10.148280+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T05:13:10.148280+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)   
2021-05-29T05:13:10.148280+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) 
2021-05-29T05:13:10.148281+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T05:13:10.200115+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T05:13:10.283484+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T05:17:48.336323+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=3f033042-c6d3-4c4b-bdbe-d0badd2d3d34 fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T05:23:09.940782+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T05:23:13.553102+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-05-29T05:23:16.251662+00:00 app[web.1]: /app/node_modules/express-rate-limiter/index.js:13
2021-05-29T05:23:16.251678+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T05:23:16.251678+00:00 app[web.1]: ^
2021-05-29T05:23:16.251679+00:00 app[web.1]:
2021-05-29T05:23:16.251679+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function
2021-05-29T05:23:16.251680+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T05:23:16.251680+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:49)
2021-05-29T05:23:16.251681+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T05:23:16.251681+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T05:23:16.251682+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T05:23:16.251682+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)   
2021-05-29T05:23:16.251683+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) 
2021-05-29T05:23:16.251683+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T05:23:16.318206+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T05:23:16.378564+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T05:24:33.000000+00:00 app[api]: Build started by user [email protected]
2021-05-29T05:25:34.946347+00:00 app[api]: Release v89 created by user [email protected]
2021-05-29T05:25:34.946347+00:00 app[api]: Deploy c8670dff by user [email protected]
2021-05-29T05:25:35.219700+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T05:25:37.000000+00:00 app[api]: Build succeeded
2021-05-29T05:25:38.314459+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-05-29T05:25:40.788755+00:00 app[web.1]: /app/node_modules/express-rate-limiter/index.js:13
2021-05-29T05:25:40.788776+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T05:25:40.788777+00:00 app[web.1]: ^
2021-05-29T05:25:40.788778+00:00 app[web.1]:
2021-05-29T05:25:40.788778+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function
2021-05-29T05:25:40.788779+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T05:25:40.788779+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:49)
2021-05-29T05:25:40.788779+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T05:25:40.788780+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T05:25:40.788780+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T05:25:40.788780+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)   
2021-05-29T05:25:40.788781+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) 
2021-05-29T05:25:40.788781+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T05:25:40.864253+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T05:25:40.952164+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T05:34:33.335208+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=3a904ea7-930c-42e6-a9af-16e333a4064a fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T05:37:25.482013+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=ebd52cb6-bb09-481b-bdb7-91d8c8993766 fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T05:37:26.504268+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=revivaproject.herokuapp.com request_id=f7f3e1ec-ea62-4ea9-8712-b1178c56abca fwd="49.245.39.161" dyno= 
connect= service= status=503 bytes= protocol=https
2021-05-29T05:38:36.526750+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=0402ac65-49cb-4b09-a44e-6aaf428c23dd fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T05:38:37.438382+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=revivaproject.herokuapp.com request_id=4389454b-a233-45d8-bf60-a3f0e7349504 fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T06:09:11.655622+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T06:09:15.444774+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-05-29T06:09:17.936977+00:00 app[web.1]: /app/node_modules/express-rate-limiter/index.js:13
2021-05-29T06:09:17.937002+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T06:09:17.937003+00:00 app[web.1]: ^
2021-05-29T06:09:17.937003+00:00 app[web.1]:
2021-05-29T06:09:17.937003+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function
2021-05-29T06:09:17.937004+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T06:09:17.937004+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:49)
2021-05-29T06:09:17.937005+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T06:09:17.937005+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T06:09:17.937005+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T06:09:17.937006+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)
2021-05-29T06:09:17.937006+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
2021-05-29T06:09:17.937007+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T06:09:17.980716+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T06:09:18.047009+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T06:48:19.910733+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=b65d1d7c-50b2-4b63-b305-400459ed69ba fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T06:48:21.301919+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=revivaproject.herokuapp.com request_id=61fe1968-f463-4c52-b3a8-8d517d0a157d fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T06:48:33.577825+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=9831ac5d-869a-4f05-a2f3-6a0422efba77 fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T06:48:34.410206+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=revivaproject.herokuapp.com request_id=cd55e067-ced5-4689-a815-5725e7daa151 fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https
2021-05-29T06:55:56.000000+00:00 app[api]: Build started by user [email protected]
2021-05-29T06:56:52.630557+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T06:56:52.473357+00:00 app[api]: Deploy e28a52be by user [email protected]
2021-05-29T06:56:52.473357+00:00 app[api]: Release v90 created by user [email protected]
2021-05-29T06:56:54.000000+00:00 app[api]: Build succeeded
2021-05-29T06:56:55.920729+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-05-29T06:56:58.334876+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T06:56:58.401966+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T06:56:58.405968+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-29T06:56:58.278359+00:00 app[web.1]: /app/node_modules/express-rate-limiter/index.js:13
2021-05-29T06:56:58.278373+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T06:56:58.278374+00:00 app[web.1]: ^
2021-05-29T06:56:58.278374+00:00 app[web.1]: 
2021-05-29T06:56:58.278374+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function    
2021-05-29T06:56:58.278375+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T06:56:58.278375+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:52)
2021-05-29T06:56:58.278375+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T06:56:58.278376+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T06:56:58.278376+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T06:56:58.278376+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)
2021-05-29T06:56:58.278377+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
2021-05-29T06:56:58.278377+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T06:57:01.716901+00:00 heroku[web.1]: Starting process with command `node dist/server.js`
2021-05-29T06:57:04.120156+00:00 heroku[web.1]: Process exited with status 1
2021-05-29T06:57:04.188477+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-29T06:57:04.078916+00:00 app[web.1]: /app/node_modules/express-rate-limiter/index.js:13
2021-05-29T06:57:04.078967+00:00 app[web.1]: this.__configuration = this.__buildConfiguration(options);
2021-05-29T06:57:04.078967+00:00 app[web.1]: ^
2021-05-29T06:57:04.078968+00:00 app[web.1]:
2021-05-29T06:57:04.078968+00:00 app[web.1]: TypeError: this.__buildConfiguration is not a function
2021-05-29T06:57:04.078982+00:00 app[web.1]: at module.exports (/app/node_modules/express-rate-limiter/index.js:13:33)
2021-05-29T06:57:04.078983+00:00 app[web.1]: at Object.<anonymous> (/app/dist/server.js:34:52)
2021-05-29T06:57:04.078983+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:774:30)
2021-05-29T06:57:04.078983+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2021-05-29T06:57:04.078983+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:641:32)
2021-05-29T06:57:04.078984+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)
2021-05-29T06:57:04.078984+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
2021-05-29T06:57:04.078984+00:00 app[web.1]: at internal/main/run_main_module.js:17:11
2021-05-29T06:57:05.387430+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=revivaproject.herokuapp.com request_id=54289191-9ec6-4ca9-ad4c-49395f5b3bf4 fwd="49.245.39.161" dyno= connect= service= status=503 bytes= protocol=https


Solution 1:[1]

At line 5, you need to import 'express-rate-limit' not 'express-rate-limiter'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MALAYALI HACKERZ