localbase icon indicating copy to clipboard operation
localbase copied to clipboard

Uncaught ReferenceError: require is not defined

Open maifeeulasad opened this issue 3 years ago • 8 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

maifeeulasad avatar Dec 28 '22 06:12 maifeeulasad

Same issue:

Uncaught ReferenceError: require is not defined

raul-ortega avatar Dec 29 '22 11:12 raul-ortega

@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.

maifeeulasad avatar Dec 29 '22 11:12 maifeeulasad

I'm using vue3 + vite. I solved the issue following the commit of a PR: https://github.com/dannyconnell/localbase/pull/72/commits/2683c67066021a7c3eb301b4724753c014bb84bf

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

raul-ortega avatar Dec 30 '22 11:12 raul-ortega

I'm facing same issue.

mpincipientinfo avatar Jan 03 '23 07:01 mpincipientinfo

Uncaught ReferenceError: require is not defined

I'm facing the same issue.

devloperabhishek avatar Jan 03 '23 07:01 devloperabhishek

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.

Erik-Bjerke avatar Jan 24 '23 05:01 Erik-Bjerke

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

Cornstar23 avatar Jul 26 '23 03:07 Cornstar23

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

Stretsh avatar Nov 19 '23 12:11 Stretsh

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!

rborowski avatar Jan 09 '24 14:01 rborowski

Closing here because it has been fixed in the version 0.7.6. https://github.com/dannyconnell/localbase/pull/84

samuk190 avatar Jun 06 '24 08:06 samuk190

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.

samuk190 avatar Jun 06 '24 08:06 samuk190