我正在尝试使用gatsby在博客构建中添加OfficeUI fabric组件。
一旦我导入任何组件,站点就会停止工作。
使用develop命令,我可以在浏览器控制台中看到:SyntaxError: export declarations may only appear at top level of a module
怎么解决这个问题?(我对节点开发非常陌生)。
我做过的搜索显示了babel没有使用es2015预置的问题。但是,我反复检查了一下,.babelrc文件提到了这个预设。
下面是我所做的全部操作(如果有关系的话,在Windows10 x64上):
SyntaxError: export declarations may only appear at top level of a module我提供了一个完整的复制库:https://github.com/stevebeauge/repro-gatsbyjs-officeui-error
编辑挖掘一下我可以在生成的'common.js‘文件中看到错误:
/***/ "./node_modules/office-ui-fabric-react/lib/Button.js":
/***/ (function(module, exports) {
export * from './components/Button/index';
//# sourceMappingURL=Button.js.map
/***/ }),这里的出口似乎是被禁止的,这导致了Babel问题(尽管没有找到解决的办法)。
发布于 2018-07-23 09:23:22
最近我偶然发现了类似的错误,我的解决方案是显式地从lib-commonjs导入:
import { Button } from 'office-ui-fabric-react/lib-commonjs/Button'; 而不是
import { Button } from 'office-ui-fabric-react/lib/Button'由于babel没有将office-ui-fabric-react转换为CommonJS模块,所以出现了错误。
https://stackoverflow.com/questions/51328448
复制相似问题