在我的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)
...如果看起来很眼熟,请给我建议。
发布于 2020-12-10 15:18:36
目前,在nodejs上下文中使用/导入lightweight-charts是不可能的。你可以在https://github.com/tradingview/lightweight-charts/issues/488上订阅,当问题得到解决时会收到通知。
发布于 2021-02-24 03:53:34
这可能不是修复根本原因的完美解决方案,但我能够通过package.json中的jest选项修复错误。
...
"transformIgnorePatterns": [
"node_modules/(?!(lightweight-charts|fancy-canvas)/)"
]https://stackoverflow.com/questions/65226025
复制相似问题