ember-cli-mirage 和 babel 错误

Posted

技术标签:

【中文标题】ember-cli-mirage 和 babel 错误【英文标题】:ember-cli-mirage and babel error 【发布时间】:2018-03-17 14:27:01 【问题描述】:

我正在关注本教程:https://guides.emberjs.com/v2.8.0/tutorial/installing-addons/

当我开始添加 ember-cli-mirage 时,它​​会出现构建错误并且不会加载应用程序:

Richards-MacBook-Air:super-rentals rpt$ ember s
WARNING: Node v8.9.1 has currently not been tested against Ember CLI and may result in unexpected behaviour.

Just getting started with Ember? Please visit http://localhost:4200/ember-getting-started to get going

Livereload server on http://localhost:49154
Serving on http://localhost:4200/
 Error: read ECONNRESET
    at _errnoException (util.js:1024:11)
    at TLSWrap.onread (net.js:615:25)
 code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' 
File: ember-cli-mirage/utils/inflector.js
The Broccoli Plugin: [broccoli-persistent-filter:Babel] failed with:
SyntaxError: ember-cli-mirage/utils/inflector.js: Unexpected token (4:14)
export  singularize, pluralize  from 'ember-inflector';

export  Ember.String.capitalize as capitalize, Ember.String.camelize as camelize, Ember.String.dasherize as dasherize, Ember.String.underscore as underscore ;
    at Parser.pp.raise (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:82:8)
    at Parser.pp.expect (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:76:33)
    at Parser.pp.parseExportSpecifiers (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:772:12)
    at Parser.pp.parseExport (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:701:28)
    at Parser.parseExport (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:713:20)
    at Parser.pp.parseStatement (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:115:90)
    at Parser.parseStatement (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:655:22)
    at Parser.pp.parseTopLevel (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:30:21)
    at Parser.parse (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/parser/index.js:70:17)
    at Object.parse (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/node_modules/babylon/lib/index.js:45:50)
    at Object.exports.default (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/lib/helpers/parse.js:36:18)
    at File.parse (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/lib/transformation/file/index.js:574:40)
    at File.parseCode (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/lib/transformation/file/index.js:691:20)
    at /Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/lib/transformation/pipeline.js:167:12
    at File.wrap (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/lib/transformation/file/index.js:639:16)
    at Pipeline.transform (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/babel-core/lib/transformation/pipeline.js:165:17)
    at /Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/lib/parallel-api.js:123:26
    at initializePromise (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:567:5)
    at new Promise (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:1039:33)
    at Object.transformString (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/lib/parallel-api.js:117:12)
    at Babel.transform (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/index.js:110:22)
    at Babel.processString (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/index.js:216:15)
    at Promise.then.result.output (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/broccoli-persistent-filter/lib/strategies/persistent.js:41:23)
    at initializePromise (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:567:5)
    at new Promise (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:1039:33)
    at /Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/broccoli-persistent-filter/lib/strategies/persistent.js:40:18
    at tryCatch (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:538:13)
    at publish (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:508:7)
    at flush (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:2415:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)


The broccoli plugin was instantiated at: 
    at Babel.Plugin (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/broccoli-persistent-filter/node_modules/broccoli-plugin/index.js:7:31)
    at Babel.Filter [as constructor] (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/node_modules/broccoli-persistent-filter/index.js:64:10)
    at new Babel (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/broccoli-babel-transpiler/index.js:37:10)
    at EmberApp._addonTree (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:910:29)
    at EmberApp._processedVendorTree (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:944:20)
    at EmberApp._processedExternalTree (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:975:21)
    at EmberApp.appAndDependencies (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:1071:30)
    at EmberApp.javascript (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:1201:34)
    at EmberApp.toArray (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:1606:10)
    at EmberApp.toTree (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/broccoli/ember-app.js:1628:30)
    at module.exports (/Users/rpt/projects/super-rentals/ember-cli-build.js:23:14)
    at Class.setupBroccoliBuilder (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/models/builder.js:74:19)
    at Class.init (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/models/builder.js:54:10)
    at Class.superWrapper [as init] (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/core-object/lib/assign-properties.js:32:18)
    at new Class (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/core-object/core-object.js:32:33)
    at Class.run (/Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/tasks/serve.js:15:19)
    at /Users/rpt/projects/super-rentals/node_modules/ember-cli/lib/commands/serve.js:76:24
    at tryCatch (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:525:12)
    at invokeCallback (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:538:13)
    at /Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:606:14
    at flush (/Users/rpt/projects/super-rentals/node_modules/ember-cli/node_modules/rsvp/dist/rsvp.js:2415:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

谁能指出我出了什么问题的正确方向?

我正在使用 ember 2.8.0 并使用最新版本的 ember-cli-mirage。

请记住,我真的是 ember 新手。

【问题讨论】:

【参考方案1】:

您开始使用 Ember 2.8 是否有特定原因?除非有,否则我建议完全删除 Ember-CLI (npm uninstall -g ember-cli) 并从 Ember 3.0 重新开始。

我建议这样做的原因是,您在那里看到的错误看起来是由于 Mirage 期望在最新版本的 Mirage 中进行的 Babel 升级,但在您安装的旧版本 Ember 中不存在。

【讨论】:

我正在尝试学习 2.8.0,因为这是我将要从事的项目将使用的。我想你不知道我应该使用哪个版本的 Mirage?还是我只需要安装每个版本,看看哪个有效?

以上是关于ember-cli-mirage 和 babel 错误的主要内容,如果未能解决你的问题,请参考以下文章

如何在 ember-cli-mirage 中创建对象?

使用 ember-cli-mirage 测试错误响应

Ember.js - 将 ember-cli-mirage 用于假模型时未找到模型

Ember 数据模型中的计算属性不适用于 ember-cli-mirage 模型

当模型被侧载时,ember-cli-mirage 失去关系

Ember Mirage 没有将模型作为 ember 对象传递