首页 > 解决方案 > nestjs 中的 chartiq 必须使用 import 来加载 ES Module

问题描述

我正在尝试在 NestJs 中使用 chartiq 学习计算器,它会引发以下错误:

internal/modules/cjs/loader.js:1092
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: A:\projects\chartiq-service\chartiq-service\node_modules\chartiq\modules\studycalc\study-calculator.js
require() of ES modules is not supported.
require() of A:\projects\chartiq-service\chartiq-service\node_modules\chartiq\modules\studycalc\study-calculator.js from A:\projects\chartiq-service\chartiq-service\dist\chartiq\services\chartiq.service.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename study-calculator.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from A:\projects\chartiq-service\chartiq-service\node_modules\chartiq\package.json.

我怎样才能解决这个问题?我只是想导入它,App 不断抛出这个异常

标签: node.jsnestjschartiq

解决方案


推荐阅读