流星,阿波罗& Sequelize:找不到模块'config.json'

时间:2016-08-17 09:40:11

标签: meteor sequelize.js apollo sequelize-cli

最近在apollo和sequelize之间添加了一个全新安装的流星,创建了一个按照要求工作的.sequelizerc文件,但每当我运行meteor时它都失败了:错误:找不到模块'/ lib / database / mysql / models / .. config.json'

申请结构:

/.meteor
/client
/lib
    /database
        /mysql
            /migrations
            /models
                index.js
            /seeders
            config.json
/node_modules
    /.bin
        .sequelizerc
/server

.sequelizerc file

var path = require('path');

module.exports = {
    'config': path.resolve('../../lib/database/mysql', 'config.json'),
    'migrations-path': path.resolve('../../lib/database/mysql', 'migrations'),
    'models-path': path.resolve('../../lib/database/mysql', 'models'),
    'seeders-path': path.resolve('../../lib/database/mysql', 'seeders'),
}

/lib/database/models/index.js文件

var fs        = require('fs');
var path      = require('path');
var Sequelize = require('sequelize');
var basename  = path.basename(module.filename);
var env       = process.env.NODE_ENV || 'development';
var config    = require(__dirname + '/..\config.json')[env];
var db        = {};

if (config.use_env_variable) {
    var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
    var sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
    .readdirSync(__dirname)
    .filter(function(file) {
        return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
    })
    .forEach(function(file) {
        var model = sequelize['import'](path.join(__dirname, file));
        db[model.name] = model;
    });

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

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

的package.json

{
    "name": "meteor-apollo-sequelize",
    "private": true,
    "scripts": {
        "start": "meteor run"
    },
    "dependencies": {
        "apollo-client": "^0.3.12",
        "apollo-server": "^0.1.1",
        "express": "^4.14.0",
        "graphql": "^0.6.2",
        "graphql-tools": "^0.6.4",
        "meteor-node-stubs": "^0.2.3",
        "mysql": "^2.11.1",
        "sequelize": "^3.24.0",
        "sequelize-cli": "^2.4.0"
    }
}

1 个答案:

答案 0 :(得分:2)

修正反斜杠/正斜杠 - 更改此行:

var config = require(__dirname + '/..\config.json')[env];

var config = require(__dirname + '/../config.json')[env];