PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

Error: Cannot find module "." #55

Closed sahibalejandro closed 6 years ago

sahibalejandro commented 6 years ago

Hi, I'm getting this error when instantiating a new store with new OpenRecord(...)

/node_modules/openrecord/lib/utils.js:88
    var plugin = require(files[i])
^
Error: Cannot find module "."

This is my code:

const OpenRecord = require('openrecord')

module.exports = new OpenRecord({
    type: 'mysql',
    host: '127.0.0.1',
    database: 'database',
    username: 'user',
    password: 'secret'
})

Am I doing something wrong?

I'm using webpack.

PhilWaldmann commented 6 years ago

Hi, version 1 of OpenRecord currently does not work with webpack or similar bundler. This is something I want to resolve in V2.

arthurfranca commented 6 years ago

On development, using node -r babel-register server.js to start a server with es6 imports and all other es6 stuff and using webpack-dev-middleware works fine if i do:

Buffer.toString = () => 'any text unlikely used elsewhere' // Before using OpenRecord

export default new OpenRecord({
 ...,
 models: path.join(__dirname, '..', 'models', '**', '*')
})

and using this on model files:

module.exports = function () { } // instead of export default

It seems a bug with babel when openrecord data_types.js setting tries to use Buffer as a json key. Not so much related to this issue, but also a problem when trying to use OpenRecord with modern tools like babel.

I thought production code was working, but after seeing this issue, i compiled server code with webpack (although old version 1.12.14) to one file and same problem described by @sahibalejandro happens on Store.loadModels > Utils.require when i run compiled file. It is unable to find first model on folder: Error: Cannot find module 'src/models/modelname.js'

PhilWaldmann commented 6 years ago

version 2 will support webpack. Although without support to load models e.g. via models: path.join(__dirname, '..', 'models', '**', '*'). But I'm working on a webpack plugin to solve this

arthurfranca commented 6 years ago

Any luck with the webpack plugin? Looking at v2 roadmap large backlog, the release seems too far away =(

PhilWaldmann commented 6 years ago

Take a look at branch v2 or checkout openrecord@next

I‘ll Release Version 2 in the comming weeks!

Am 01.03.2018 um 22:11 schrieb arthurfranca notifications@github.com:

Any luck with the webpack plugin? Looking at v2 roadmap large backlog, the release seems too far away =(

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

PhilWaldmann commented 6 years ago

version 2.0 released