本地运行出错,需要自己手动修改依赖的引入 #16

Closed
opened 2026-02-16 10:15:48 -05:00 by yindo · 1 comment
Owner

Originally created by @jonnzer on GitHub (Jan 29, 2024).

error - ./node_modules/.pnpm/ahooks@3.7.9_react@18.2.0/node_modules/ahooks/lib/utils/lodash-polyfill.js:14:0
Module not found: ESM packages (lodash-es) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

类似这样的错误,在install包之后,本地开始运行npm run dev就会出现。

举个例子, 其中底层是引用的lodash-es 库,比如node_modules.pnpm\ahooks@3.7.9_react@18.2.0\node_modules\ahooks\lib\useReactive\index.js。这里引用了var _lodashEs = require("lodash-es");

这里会报错,报错原因和解决方式参考这个链接:
Module not found: ESM packages (lodash-es) need to be imported. Use 'import' to reference the package instead. 官方解决

也就是require改为import。

还是不推荐开发者在下好依赖,还要手动修改依赖。期望修复或者有其他建议。

Originally created by @jonnzer on GitHub (Jan 29, 2024). error - ./node_modules/.pnpm/ahooks@3.7.9_react@18.2.0/node_modules/ahooks/lib/utils/lodash-polyfill.js:14:0 Module not found: ESM packages (lodash-es) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals 类似这样的错误,在install包之后,本地开始运行npm run dev就会出现。 举个例子, 其中底层是引用的lodash-es 库,比如node_modules\.pnpm\ahooks@3.7.9_react@18.2.0\node_modules\ahooks\lib\useReactive\index.js。这里引用了var _lodashEs = require("lodash-es"); 这里会报错,报错原因和解决方式参考这个链接: Module not found: ESM packages (lodash-es) need to be imported. Use 'import' to reference the package instead. [官方解决](https://nextjs.org/docs/messages/import-esm-externals) 也就是require改为import。 还是不推荐开发者在下好依赖,还要手动修改依赖。期望修复或者有其他建议。
yindo closed this issue 2026-02-16 10:15:48 -05:00
Author
Owner

@jonnzer commented on GitHub (Feb 2, 2024):

后来换了设备用高版本node,v20.11.0,没出错了,不好意思~~~

@jonnzer commented on GitHub (Feb 2, 2024): 后来换了设备用高版本node,v20.11.0,没出错了,不好意思~~~
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/webapp-conversation#16