Using localForage and angular-localForage with Browserify causing errors with require statements

StackOverflow https://stackoverflow.com/questions/23573700

Вопрос

I am attempting to install localForage into a node.js application (with Angular) and Browserify.

Here is a link to the localForage documentation

It appears that using localForage and angular-localForage causes a problem with browserify based around the use of 'require'


If I require the localforage.js file in the src file I get the following error:

Warning: module "promise" not found from "/Users/mgayhart/Sites/epson-    receipts/bower_components/localforage/src/localforage.js" Use --force to continue.

If I require the localforage.js file in the dist file, I get the following error:

Warning: module "./drivers/indexeddb" not found from "/Users/mgayhart/Sites/epson-  receipts/bower_components/localforage/dist/localforage.js" Use --force to continue.

Anyone know of a workaround to be able to move forward with these libraries?

Это было полезно?

Решение 2

For me installing it through bower and using it with browserify-shim worked. So in package.json:

"browser": {
   "localforage":"./src/lib/vendor/localforage/dist/localforage.min.js"
},

"browserify-shim": {
   "localforage":"localforage"
}

And to expose it as an angular-service (if you don't want to use angular-localforage):

app.factory "localforage",-> require 'localforage'

Другие советы

There is an issue on github with this problem: https://github.com/ocombe/angular-localForage/issues/26 I'll be working on it soon, you can subscribe to the github notifs on this issue to know when it's fixed !

I've just been having this issue myself tonight, but I think I found a fix.

Instead of trying to get the bower modules to work with browserify, why not just use npm like its made for?

npm install localforage and then when you use require you don't have to give it the path

but it still didn't work for me until I copied the folder: localforage/src/drivers TO localforage/dist/drivers

Then it found all the dependencies and worked like a champ!

Alternatively if you must use bower you could try to use the debowerify tranform w/ gulp: https://github.com/eugeneware/debowerify

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top