11

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?

Marcio Junior
  • 19,078
  • 4
  • 44
  • 47
Dmitro
  • 1,489
  • 4
  • 22
  • 40

2 Answers2

32

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

Chirag Ravindra
  • 4,760
  • 1
  • 24
  • 35
Marcio Junior
  • 19,078
  • 4
  • 44
  • 47
0

I had the same issue and it was solved by @Marcio's solution. BUT I also needed to update my node version.

The issue persisted on node-v0.10.0, I updated node to node-v0.12.0 and then @Marcio's solution worked.

To be clear, you should still do everything in @Marcio's post, but if it still does not solve the issue, try updating node.

mpd
  • 2,223
  • 1
  • 19
  • 23