Can't import sequelize module into test (Jest, Sequelize, sqlite)

I even tried importing sequelize directly into my test file and it gives the same message.

Can someone help me to figure this out?

My GitHub repo

 FAIL  src/tests/db_controller.test.js
  ● Test suite failed to run

    Cannot find module 'sequilize' from 'app.js'

    > 1 | const Sequelize = require("sequilize");
        | ^
      2 | const db_options = require("./databases/database.options.json");
      3 | 
      4 | const test_db = new Sequelize(db_options.test);

      at Resolver.resolveModule (../../../../usr/lib/node_modules/jest/node_modules/jest-resolve/build/index.js:259:17)
      at Object.<anonymous> (src/app.js:1:1)

You’re spelling “sequelize” wrong, there isn’t a module called “sequilize”

I pasted the wrong error

Here is the correct one.

would you mind cloning it to see if it works for you? im using ubuntu btw incase that matters.

Your syntax is wrong I think. I don’t really use node much and use ES6 modules when I do so someone else will need to confirm it, but you’ve got

module.exports.DBController = DBController

When it should be

exports.DBController = DBController

Or

module.exports = {
  DBController
}

The “require is not a function error” is either because you’re trying to call a require-d thing as a function when it isn’t a function or you have a circular dependency. It’s not the latter, so it has to be the former, and I think it’s because you aren’t importing what you think you’re importing, then trying to call it.

and you are trying to use Sequelize in mock_db.config.js without importing it.

If i call sequelize in app.js and use it it works. its just when I try to import my module into a test file it doesnt work. also require works for every other module with either syntax that you mentioned. i understand js is isnt your thing but thx for the reply

also i didnt push the changes yet to my repo. ill send you a new link

that repo is current

Then if that is definitely not the issue (+ the missing Sequelize import was definitely missing in the test config file in the original link you posted, but updated one does not have the issue), it seems likely that you have a circular dependency - ie requiring some module that requires the original module, which means one of those require functions is null, which means you are attempting to execute null, hence “require is not a function”. require is just a function, so for you to get that error it is likely that you are attempting to execute require when the value of it is not executable. I can’t run this on my phone so I’m afraid I can’t offer anything further atm

There were some issues with Jest mocking a while ago but you don’t seem to have the affected versions, would be worth ensuring you nuke node_modules then ensure everything is up to date and reinstall

so i nuked node_modules and ran npm install and it still has the same issue. also i noticed for some reason when i imported sequelize to app.js it automatically creates the appropriate db file without me running the script (which is weird but yeh sure). its just when i try to run tests with it that it doesnt work. the methods even work fine in the app file, so i know sequelize is importing properly, atleast to app.js. also i have to same issue even without using mock

I’m probably not the right person to help with this but if you remove automock from the jest config it fails for the require on the models instead (because it’s not there).

Cannot find module '../models/build_model' from 'db_controller.test.js'