【问题标题】:How to fix `SyntaxError: Unexpected token export` when using fabric-ui-foundation使用fabric-ui-foundation时如何修复`SyntaxError: Unexpected token export`
【发布时间】:2020-01-06 01:16:30
【问题描述】:
  1. 我有一些使用@uifabric/foundation npm 包的通用 TS 库。 这个库公开了一些基于 uifabric 代码风格和模式的 React 组件。
  2. 还有一个使用此库的 TS/React/Redux 项目(使用 npm 链接)。编译和工作没有问题。
  3. 该项目包含一些测试场景。使用的堆栈:mocha, enzyme, sinon, chai。编译没有问题,但是在执行 mocha 测试时,我不断得到 ​​li>
[sharedlibpath]\node_modules\@uifabric\utilities\lib\index.js:1
(function (exports, require, module, __filename, __dirname) { export * from './Async';
                                                              ^^^^^^

SyntaxError: Unexpected token export

检查了失败的组件的输出 js 文件,这是行 var lib_1 = require("@uifabric/utilities/lib");

谁能解释一下如何解决这个问题?

【问题讨论】:

    标签: typescript node-modules office-ui-fabric


    【解决方案1】:

    更新:模块分辨率似乎有问题。编译不同,测试运行不同。 MS Fabric Wiki 中描述了jest 的解决方案:https://github.com/OfficeDev/office-ui-fabric-react/wiki/Fabric-6-Release-Notes

    但是当我的组件不是从 @uifabric/utilities/lib 而是从 @uifabric/utilities/lib-commonjs 导入时,这会导致:"Cannot find module" when running unit tests on node.js with react as peer dependency in common package

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多