Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import module ember-localstorage-adapter with Ember-CLI?

I tried to import ember-localstorage-adapter as

import DS.LSAdapter from "ember-localstorage-adapter";

But I got the error

Error: Line 5: Missing from after import

Do I need to compile ember-localstorage-adapter with ES6 Module Transpiler?

like image 494
Dmitro Avatar asked Jun 20 '14 12:06

Dmitro


1 Answers

UPDATE

ember-localstorage-adapter is now an ember-cli addon, so to add it to asset pipeline just run:

ember install ember-localstorage-adapter for latest ember-cli versions (after 1.5)

or

npm install --save-dev ember-localstorage-adapter for versions before 1.5

And go to step 4, to configure the adapter and serializer.

If you're using an old version of ember-cli, please use the steps below:

I did the following steps to import the ember-localstorage-adapter:

1- Created a new ember application with:

ember new <someapp>

2- Installed the ember-localstorage-adapter dependency with bower:

bower install ember-localstorage-adapter --save

3- Added the app.import("bower_components/ember-localstorage-adapter/localstorage_adapter.js"); before the module.exports = app.toTree(); call inside of Brocfile.js

This is the entire Brocfile.js:

/* global require, module */

 var EmberApp = require('ember-cli/lib/broccoli/ember-app');

 var app = new EmberApp(); 

 app.import("bower_components/ember-localstorage-adapter/localstorage_adapter.js");

 module.exports = app.toTree();

4- Used the DS.LSAdapter as the default adapter creating a file called app/adapters/application.js with the following content:

import DS from 'ember-data';

export default DS.LSAdapter.extend({
  namespace: 'yournamespace'
});

5- Used the DS.LSSerializer as the default serializer creating a file called app/serializers/application.js with the following content:

import DS from 'ember-data';

export default DS.LSSerializer.extend();

I hope it helps

like image 172
Marcio Junior Avatar answered Nov 01 '22 00:11

Marcio Junior