Error: Module node_modules/@ionic/storage/dist/es5/index.js does not export Storage


#1

After install the module using:

npm install @ionic/storage --save --save-exact

Add it to NgModule:

    import { Storage } from '@ionic/storage';

...

@NgModule({
  ...
  providers: [Storage]
})

And import/use in my component, I am getting this error when serving:

 Error: Module node_modules/@ionic/storage/dist/es5/index.js does not export Storage

at Module.trace (/node_modules/rollup/dist/rollup.js:7677:29)  

Any help, please?


#2

I’m getting this too. Have you found a fix?


#3

Not yet!

I am trying, but if I can’t, finally I will use the localforage module…


#4

I think I got it.

I had to modify ionic rollup.config.js

plugins: [
ngTemplate(),
commonjs({
    include: [
    'node_modules/rxjs/**',
    'node_modules/angularfire2/**',
    'node_modules/firebase/**',
    'node_modules/@ionic/storage/**'
    ],
    namedExports: {
    'node_modules/angularfire2/node_modules/firebase/firebase.js': ['initializeApp', 'auth', 'database'],
    'node_modules/angularfire2/node_modules/firebase/firebase-browser.js': ['initializeApp', 'auth', 'database']
    
    }
}),
nodeResolve({
  module: true,
  jsnext: true,
  main: true,
  browser: true,
  extensions: ['.js']
})

]

the line that matters is the commonjs include ‘node_modules/@ionic/storage/**’


#5

Thank you! It works!

:slight_smile:


#6

I had the same problem, but now i can’t inject the storage, i always get:

TypeError: this._db.config is not a function
at new Storage (storage.js:38)
at NgModuleInjector.get (AppModule.ngfactory.js:343)
at NgModuleInjector.AppModuleInjector.getInternal (AppModule.ngfactory.js:509)
at NgModuleInjector.get (ng_module_factory.js:94)
at ElementInjector.get (element_injector.js:29)
at DebugAppView.View_MyApp_Host0.createInternal (MyApp_Host.ngfactory.js:16)
at DebugAppView.AppView.create (view.js:125)
at DebugAppView.create (view.js:337)
at ComponentFactory.create (component_factory.js:153)
at ViewContainerRef
.createComponent (view_container_ref.js:114)

Any ideas?


#7

I get the same error if i change the rollup.config with this version at the conference app from the ionic team.

Is this really working for you?


#8

I didnt actually test it until now and I’m getting the same error =[


#9

Try adding ‘node_modules/localforage/**’ to the rollup.config too.

I’m having other issues and still cant test it, but it got me past the this._db.config not a function issue.


#10

Ah, thank you very much. Now everything is working!


#11

Hm, now i have the next issue. When i call the set method of storage, i get the error:
error_handler.js:45
EXCEPTION: Uncaught (in promise): DataCloneError: Failed to execute ‘put’ on ‘IDBObjectStore’: An object could not be cloned.

Do you know what the problem could be?

Edit: Okay, i found the reason for this error: It’s not possible to put JSON-Data in the DB. I think i should parse it to a string or something like this. Not sure for now.


#12

how do you get to this file? rollup.config.js