Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__requireContext is not defined #12

Open
antrannguyen opened this issue Dec 28, 2020 · 2 comments
Open

__requireContext is not defined #12

antrannguyen opened this issue Dec 28, 2020 · 2 comments

Comments

@antrannguyen
Copy link

Getting this error, when it's looking for the process.env.NODE_ENV before the require.context is called in the models index.js file

if (process.env.NODE_ENV === 'development') {
require('babel-plugin-require-context-hook/register')();
}

export default (sequelize) => {
let db = {};

const context = require.context('.', true, /^./(?!index.js).*.js$/, 'sync');

context
.keys()
.map(context)
.forEach((module) => {
const model = module(sequelize, Sequelize);
db[model.name] = model;
});

Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

return db;
};

@markhorgan
Copy link

process.env.NODE_ENV might be undefined and require('babel-plugin-require-context-hook/register')() might not be called. Try adding console.log(process.env.NODE_ENV) above it.

You might need to set NODE_ENV in package.json:

scripts: {
  "server": "set NODE_ENV=development && nodemon --exec babel-node --watch src/server src/server/index.js"
}

@ankurkapil8
Copy link

@markhorgan

This plugin is not working for me.Below is my code. I am using jest.

require('babel-plugin-require-context-hook/register')();
const context = require.context('./', false, /.ts|.js$/);
const keys = context
.keys()
.filter(item => item.indexOf('d.ts') === -1 && item !== './index.ts' && item !== './index.js');

const models = [];

for (const key of keys) {
models.push(context(key));
}
export default models;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants