Jest + WebStorm + yarn workspaces = SyntaxError: 不能在模块外使用导入语句

问题描述 投票:0回答:1

跑步 yarn test 工作,但使用 IntelliJ WebStorm 运行按钮启动测试时出现以下错误。

Test suite failed to run

C:\pavel\repo\projectxy\libs\ui-components-redux\src\features\forms\__tests__\duck.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { apiErrorsToFieldErrors, apiErrorsToGeneralErrors, prepareApiErrors } from '../duck';
                                                                                         ^^^^^^

SyntaxError: Cannot use import statement outside a module

  at ScriptTransformer._transformAndBuildScript (../../node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  at ScriptTransformer.transform (../../node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
intellij-idea jestjs webstorm
1个回答
0
投票

在Jest模板中放入真实的根目录+观察Webstorm填写配置文件字段。

enter image description here

解释。Webstorm估计工作目录是package.json所在的目录,所以它猜测的是lib,而不是主package.json(有工作空间定义)。这将导致找不到配置文件。

© www.soinside.com 2019 - 2024. All rights reserved.