gpt4 book ai didi

javascript - 在 Node.js 中导入 : error "Must use import to load ES Module"

转载 作者:行者123 更新时间:2023-12-03 06:55:21 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





SyntaxError: Cannot use import statement outside a module

(32 个回答)


7 个月前关闭。




我正在尝试导入 myArr来自 你好.js 进入 index.js .但是我得到一个错误

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
文件 你好.js
export let myArr = ['hello', 'hi', 'hey'];
文件 index.js
import { myArr } from './hello.js';
console.log(myArr);
我哪里错了?

最佳答案

使用版本 2:

npm install node-fetch@2
v3 的 node-fetch 是一个 ESM-only 模块 - 你不能用 require() 导入它。
如果您无法切换到 ESM,请使用与 CommonJS 保持兼容的 v2 .将继续为 v2 发布关键错误修复。

关于javascript - 在 Node.js 中导入 : error "Must use import to load ES Module",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61670459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com