Meteor Up部署失败,但开发时应用程序运行正常。

3

我正在测试我的第一个Meteor应用程序的部署,并考虑使用Meteor Up。经过一番摸索后,我成功地运行了mup setup而没有出现任何错误,一切看起来都很好。

然而,运行mup deploy失败了:

$ mup deploy
Building App Bundle Locally
Errors prevented bundling:
While minifying app code:
eval at <anonymous>
(/home/yanick/.meteor/packages/standard-minifier-js/.1.2.1.s85ddv++os+web.browser+web.cordova/plugin.minifyStdJS.os/npm/node_modules/meteor/minifier-js/node_modules/uglify-js/tools/node.js:28:1),
<anonymous>:1545:18: SyntaxError: Unexpected token: name (Converter)
at new JS_Parse_Error (eval at <anonymous>
(/home/yanick/.meteor/packages/standard-minifier-js/.1.2.1.s85ddv++os+web.browser+web.cordova/plugin.minifyStdJS.os/npm/node_modules/meteor/minifier-js/node_modules/uglify-js/tools/node.js:28:1),
<anonymous>:1545:18) at js_error (eval at <anonymous>
...

有问题的文件似乎是一个名为Converter.js的文件,但这个文件并不复杂,只是导出一些 JSON 对象。
import Converter from 'universal-converter';

export default Converter;

export const DEFAULT_UNIT = 'unit';

export const Units = {
  'unit': {
    'type': 'unit',
    'name': 'unit'
  },
  'inch': {
    'type': 'distance',
    'name': 'inch',
    'label': 'in'
  },
  'inch2': {
    'type': 'area',
    'name': 'square inch',
    'label': 'in²'
  },
  'foot': {
    'type': 'distance',
    'name': 'foot',
    'label': 'ft'
  },
  'foot2': {
    'type': 'area',
    'name': 'square foot',
    'label': 'ft²'
  },
  'yard': {
    'type': 'distance',
    'name': 'yard',
    'label': 'yd'
  },
  'yard2': {
    'type': 'area',
    'name': 'square yard',
    'label': 'yd²'
  },
  'cm': {
    'type': 'distance',
    'name': 'centimeter',
    'label': 'cm'
  },
  'm': {
    'type': 'distance',
    'name': 'meter',
    'label': 'm'
  },
  'g': {
    'type': 'mass',
    'name': 'gram',
    'label': 'g'
  },
  'kg': {
    'type': 'mass',
    'name': 'kilogram',
    'label': 'kg'
  },
  'lb' : {
    'type': 'mass',
    'name': 'pound',
    'label': 'lb'
  },
  'oz': {
    'type': 'mass',
    'name': 'once [France]',
    'label': 'oz'
  },
  'liter': {
    'type': 'volume',
    'name': 'liter',
    'label': 'L'
  },
  'gal': {
    'type': 'volume',
    'name': 'gallon [US, liquid]',
    'label': 'Gal'
  },
  'oz_v': {
    'type': 'volume',
    'name': 'ounce [UK, liquid]',
    'label': 'oz'
  }
};

为什么meteor可以正常运行,但是创建应用程序的捆绑包失败?

更新1

我尝试过重构我的应用程序目录,移动构建文件位置,但没有改变。这个命令:meteor build ../output(路径在项目根文件夹之外)如上所述失败。


由于某些原因,Meteor 无法为客户端构建您的 npm 包。似乎 uglifyJS 正在尝试压缩您的 ES2015 代码,但未能成功。我不确定该怎么解决,但希望这个指针对您有用。 - MasterAM
看起来这是一个已知的问题。请参见#4828#5517 - MasterAM
所以,因为我在universal-converter模块中使用了class,导致构建失败,对吧? - Yanick Rochon
不仅如此。我认为这些都是 ES2015 的功能(包括对象方法的缩写符号)。您可以在发布到 npm 之前使用构建步骤(类似于这两篇文章中描述的内容:([1] (http://www.hammerlab.org/2015/07/09/bundling-and-distributing-complex-es6-libraries-in-an-es5-world/)),([2] (https://booker.codes/how-to-build-and-publish-es6-npm-modules-today-with-babel/)))。 - MasterAM
是的,对我来说很幸运,故障模块是我的,所以我将babel作为开发依赖项添加到该模块中,并添加了prepublish步骤。现在它可以部署了,但这不是一个可行的解决方案,只是一个hack。如果Meteor在开发中可以正常运行,那么它应该能够构建生产环境。我在相关问题#4828中评论了这一点。 - Yanick Rochon
1个回答

1
请查看Github上相关问题。在这个页面中,@Abernix找到了一个临时解决方案:
在您的项目根目录下,执行以下命令行:
meteor remove standard-minifier-js

meteor add abernix:standard-minifier-js@1.2.2

然后,再次尝试构建。

警告:如@Abernix所说:

请不要将此视为长期解决方案(因为保持官方软件包会更好),而是更多地了解他们的进展。在完成之前还有工作要做,但我很好奇它是否可以为您解决问题。我的软件包使用uglify-js harmony分支的2.7.5版本(仍未被视为稳定版,但可能适用于某些人)。


我忘记了这个问题(实际上,我是那个在Github上发布“相关问题”的作者!),但是,是的,这就是问题所在。移除JS缩小器可以解决问题。我还有其他与缩小器有关的问题尚未解决,但我确实看到其他人确认它可以工作。 - Yanick Rochon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接