简体   繁体   English

如何使用Ember-CLI导入模块ember-localstorage-adapter?

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

I tried to import ember-localstorage-adapter as 我试图导入ember-localstorage-adapter作为

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

But I got the error 但我得到了错误

Error: Line 5: Missing from after import 错误:第5行:导入后丢失

Do I need to compile ember-localstorage-adapter with ES6 Module Transpiler? 我是否需要使用ES6 Module Transpiler编译ember-localstorage-adapter?

UPDATE UPDATE

ember-localstorage-adapter is now an ember-cli addon, so to add it to asset pipeline just run: ember-localstorage-adapter现在是一个ember-cli插件,所以要将它添加到资产管道中,只需运行:

ember install ember-localstorage-adapter for latest ember-cli versions (after 1.5) ember install ember-localstorage-adapter用于最新的ember-cli版本(1.5之后)

or 要么

npm install --save-dev ember-localstorage-adapter for versions before 1.5 npm install --save-dev ember-localstorage-adapter for 1.5之前的版本

And go to step 4, to configure the adapter and serializer. 然后转到步骤4,配置适配器和序列化程序。

If you're using an old version of ember-cli, please use the steps below: 如果您使用的是旧版本的ember-cli,请使用以下步骤:

I did the following steps to import the ember-localstorage-adapter: 我执行了以下步骤来导入ember-localstorage-adapter:

1- Created a new ember application with: 1-创建一个新的ember应用程序:

ember new <someapp>

2- Installed the ember-localstorage-adapter dependency with bower: 2-安装了与bower的ember-localstorage-adapter依赖关系:

bower install ember-localstorage-adapter --save

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

This is the entire Brocfile.js: 这是整个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: 4-使用DS.LSAdapter作为默认适配器,创建名为app/adapters/application.js的文件,其中包含以下内容:

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: 5-使用DS.LSSerializer作为默认序列app/serializers/application.js ,创建名为app/serializers/application.js的文件,其中包含以下内容:

import DS from 'ember-data';

export default DS.LSSerializer.extend();

I hope it helps 我希望它有所帮助

I had the same issue and it was solved by @Marcio's solution. 我有同样的问题,它是由@ Marcio的解决方案解决的。 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. 问题持续存在于node-v0.10.0上,我将节点更新为node-v0.12.0,然后@ Marcio的解决方案正常工作。

To be clear, you should still do everything in @Marcio's post, but if it still does not solve the issue, try updating node. 要清楚,你仍然应该在@ Marcio的帖子中做所有事情,但如果它仍然无法解决问题,请尝试更新节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM