You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Yarn导入loadash模块时遇Module not found错误求助

解决"Module not found"错误的步骤

1. 修正Lodash的拼写错误

你代码里把lodash误写为loadash,这是导致包找不到的直接原因。先修正代码:

const _ = require('lodash'); // 修正拼写错误
const people = require('./people');

console.log(people);
console.log(_.last(people));

如果还未安装Lodash,执行以下命令安装:
npm install lodash 或 yarn add lodash

2. 确认people模块的路径与文件存在性

  • 确保你的项目目录下存在people.js(或people.json)文件,且和当前执行的代码文件在同一文件夹内
  • 如果是JSON文件,建议明确写全后缀:require('./people.json')
  • 检查文件名大小写:Linux/macOS系统区分文件名大小写,确保文件名和代码里的引用完全一致(比如不要写成People.js)

完成以上修改后,重新运行代码即可正常加载模块,并输出people数组的最后一个元素。

内容的提问来源于stack exchange,提问作者Ali Imran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 19:12:36