1

We are working on an old meteor project that is being upgraded to 1.8 and we need to be able to change some of the old meteor packages to the npm versionvs (moment for example).

The problem we have struck is that we can't seem to work out which file in the whole tree we need to put the import statements because so far, wherever we put it, we get the following error in the web console.

SyntaxError: import declarations may only appear at top level of a module 

We have tried pretty much all of the files in client including startup.js but can't crack it.

Where should these import declarations go?

4

1 回答 1

1

此消息意味着您的客户端浏览器包未正确转译。这可能有两个原因:

  • 您的 Meteor 项目不会将代码转换为 ES5 语法,例如,如果它缺少ecmascript包或 babel、babel 运行时等。
  • 您从中导入一个node_modules仍然具有此import关键字的文件:默认情况下,Meteor 假定 npm 模块已经可以按原样使用并且没有重新编译(出于性能考虑)。大多数情况下,这是因为 npm 模块的默认导入文件是 esm 格式(在 的"main"字段中指定的文件package.json),但通常也会提供转译或捆绑的形式。在这种情况下,只需显式导入 dist / transpiled 文件而不是默认包文件。

在某些情况下,某些模块不会发布这样的转译版本。在这种情况下,您必须先自己进行转译。另请参阅在 node_modules 中编译包以在浏览器中使用

于 2018-11-02T02:26:27.347 回答