[英]Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported
[英]Using import for an ESM Module in nest.js gives [ERR_REQUIRE_ESM]: require() of ES Module not supported
我将nest.js与typescript一起使用并想添加
import { DRACOLoader, GLTFLoader, TextureLoader } from 'node-three-gltf';
在我的一个模块中。 但是,这会导致以下错误
c:\m3\dist\src\gltftest\gltftest.controller.js:23
const node_three_gltf_1 = require("node-three-gltf");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module c:\m3\node_modules\node-three-gltf\build\index.js from c:\m3\dist\src\gltftest\gltftest.controller.js not supported.Instead change the require of index.js in c:\m3\dist\src\gltftest\gltftest.controller.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (c:\m3\dist\src\gltftest\gltftest.controller.js:23:27)
at Object.<anonymous> (c:\m3\dist\src\gltftest\gltftest.module.js:12:30)
而我使用的 node-three-gltf@1.0.3 只是一个 esm 模块。 导致我在我的 typescript 模块/控制器中使用 ESM 导入语法来导入 ESM 模块 node-three-gltf 并得到这个错误的奇怪情况(至少对我来说 - 对这个来说是相当新的)。
似乎是由于我的项目的 nest.js 构建将我的 ES 语法转换为 CJS 语法,因此用 require 替换了我的导入,但没有转换 node-three-gltf 模块然后抱怨。
我的 tsconfig 是这样的:
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "Node",
"target": "esnext",
...
从理论上讲,我看到以下选项:
不支持 node_modules\connect-typeorm\out' 解析从 C:\m3\dist\src\main.js 导入的 ES 模块您的意思是导入 connect-typeorm/out/index.js 吗?
所以我想知道 sb 是否可以建议我如何调整 nest.js 构建配置以对依赖项进行 esm->cjs 转换或将我指向另一个方向?
谢谢! 吨
我相信您应该在您的应用程序中使用 CJS,并使用import()
表达式来加载仅限 ESM 的 package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.