2

在我的 Create React App 中导入轻量级字符时,一切正常:

import { createChart } from 'lightweight-charts';

但是,在运行测试时:

yarn test --all

显示此错误:

● 测试套件未能运行

.../node_modules/lightweight-charts/dist/lightweight-charts.esm.development.js:7
import { bindToDevicePixelRatio } from 'fancy-canvas/coordinate-space';
^^^^^^

SyntaxError: Cannot use import statement outside a module

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
  ...

如果看起来很熟悉,请建议。

4

2 回答 2

2

目前无法lightweight-charts在 nodejs 上下文中使用/导入。您可以在https://github.com/tradingview/lightweight-charts/issues/488上订阅,以便在解决问题时收到通知。

于 2020-12-10T07:18:36.487 回答
2

它可能不是解决根本原因的完美解决方案,但我能够jest通过package.json.

...
"transformIgnorePatterns": [
      "node_modules/(?!(lightweight-charts|fancy-canvas)/)"
    ]

于 2021-02-23T19:53:34.343 回答