samuk190 / localbase

A Firebase-Style Database ... Offline!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught ReferenceError: require is not defined

maifeeulasad opened this issue · comments

localbase raises issues during production build. It says Uncaught ReferenceError: require is not defined.

When I dug a little, I found out this is the code added after I added localbase as a dependency. Truncated generated code

// relevant portion below
to true or false, e.g. { keys: true }'),this.userErrors.length)return Nu.call(this),null;{let t=t0.call(this);if(t=="collection")return this.getCollection();if(t=="doc")return this.getDocument()}}function fn(e,t){return Xa.call(this),Yr.log.call(this,e,t),{success:!0,message:e,data:t}}function Or(e){return Xa.call(this),Yr.error.call(this,e),`Error: ${e}`}let hH=require("ordered-uuid");function yH(e,t){if(e?typeof e=="object"&&!(e instanceof Array)||this.userErrors.push("Data passed to .add() must be an object. Not an array, string, number or boolean."):this.userErrors.push('No data specified in add() method. You must use an object, e.g { id: 1, name: "Bill", age: 47 }'),this.userErrors.length)Nu.call(this);else{let r=this.collectionName;return new Promise((n,a)=>{let i=null;return t?i=t:i=hH.generate(),this.lf[r].setItem(i,e).then(()=>{n(fn.call(this,`Document added to "${r}" collection.`,{key:i,data:e}))}).catch(o=>{a(Or.call(this,`Could not add Document to ${r} collection.`))})})}}function o1(e){for(var t=1;t<arguments.length;t++)for(var r in arguments[t]){var n=arguments[t][r];e[r]=n}return e}
// relevant portion above

To reproduce: https://github.com/maifeeulasad/remanage/tree/c5c387cd664714d73179e5d7612c437441d65da1

Same issue:

Uncaught ReferenceError: require is not defined

@raul-ortega localbase is using browserify , ref: https://github.com/dannyconnell/localbase/blob/master/package.json#L7-L8. This is why in some system it works; but in some system like vite or vue (which runs on vite), although this library is working on dev environment, but in production it crashes.

I'm using vue3 + vite. I solved the issue following the commit of a PR: 2683c67

After building I renamed localbase.min.js as index.js and replaced the node_module index.js with it.

I'm facing same issue.

Uncaught ReferenceError: require is not defined

I'm facing the same issue.

Hello there, for those interested I decided to fork this project to continue its development as apparently it's now abandoned.

https://www.npmjs.com/package/mis-datos

So far I've:

  • Updated packages
  • Added this minor fix/workaround
  • Updated minor things in the docs
  • Added it to the NPM registry under a new name
  • For the time being the internal name is still "localbase" to maintain compatibility and being able to use it as a drop-in replacement.

I plan to:

  • Replace some packages for more modern or adequate ones
  • Add several new features (secret for now)
  • Ensure it stay fully open source and free (not becoming something like Dexie)
  • Keep it up to date and properly maintained.

I'm using vue3 + vite. I solved the issue following the commit of a PR: 2683c67

After building I renamed localbase.min.js as index.js and replaced the node_module index.js with it.

Could you also commit the new distribution files? localbase.min.js, etc

Hello there, for those interested I decided to fork this project to continue its development as apparently it's now abandoned.

https://www.npmjs.com/package/mis-datos

I plan to:

  • [...]
  • Keep it up to date and properly maintained.

Seems like this one is also gone now... 404

I'm using vue3 + vite. I solved the issue following the commit of a PR: 2683c67

After building I renamed localbase.min.js as index.js and replaced the node_module index.js with it.

I had the same issue with my Vite+Vue3+Pinia app.
I reproduced your steps and somehow it works...
In node_modules I did as follows:

  1. in node_modules/localbase/localbase/api/actions/add.js I replaced:
    import UUID from 'ordered-uuid' instead of let UUID = require('ordered-uuid')
  2. in node_modules/localbase/dist/:
    renamed "localbase.min.js" to "index.js" and moved it to node_modules/localbase/ directory (replacing existing index.js)

Maybe it will help somebody else... Thanks!

Closing here because it has been fixed in the version 0.7.6. #84

Hello there, for those interested I decided to fork this project to continue its development as apparently it's now abandoned.

https://www.npmjs.com/package/mis-datos

So far I've:

  • Updated packages
  • Added this minor fix/workaround
  • Updated minor things in the docs
  • Added it to the NPM registry under a new name
  • For the time being the internal name is still "localbase" to maintain compatibility and being able to use it as a drop-in replacement.

I plan to:

  • Replace some packages for more modern or adequate ones
  • Add several new features (secret for now)
  • Ensure it stay fully open source and free (not becoming something like Dexie)
  • Keep it up to date and properly maintained.

Hi do you still have the "secret" features? I'll be the maintaining this project.