Next.js 找不到模块 loader.js

Posted

技术标签:

【中文标题】Next.js 找不到模块 loader.js【英文标题】:Next.js cannot find module loader.js 【发布时间】:2021-07-23 06:25:56 【问题描述】:

这是我尝试运行 npm run dev 时发生的错误。

我不明白发生了什么,我尝试了这些:删除package-lock.json,删除node_modules,重新安装npm,但没有任何效果。

PS D:\Users\user\Documents\Projects\NLW#5\podcastrnext> npm run dev

> podcastrnext@0.1.0 dev D:\Users\user\Documents\Projects\NLW#5\podcastrnext
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: no next.config.js https://nextjs.org/docs/messages/webpack5
error - ../../NLW#5/podcastrnext/node_modules/next/dist/client/dev/amp-dev.js
Error: Cannot find module 'D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\@next\react-refresh-utils\loader.js'
Require stack:
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\compiled\webpack\bundle5.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\compiled\webpack\webpack.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\next-server\server\config-utils-worker.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\next-server\server\config-utils.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\next-server\server\config.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\server\next.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\server\lib\start-server.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\cli\next-dev.js
- D:\Users\user\Documents\Projects\NLW#5\podcastrnext\node_modules\next\dist\bin\next
<i> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Node.js doesn't offer a (nice) way to introspect the ESM dependency graph yet.
<i> Until a full solution is available webpack uses an experimental ESM tracking based on parsing.
<i> As best effort webpack parses the ESM files to guess dependencies. But this can lead to expensive and incorrect tracking.
<i> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Node.js doesn't offer a (nice) way to introspect the ESM dependency graph yet.
<i> Until a full solution is available webpack uses an experimental ESM tracking based on parsing.
<i> As best effort webpack parses the ESM files to guess dependencies. But this can lead to expensive and incorrect tracking.

【问题讨论】:

【参考方案1】:

我能够解决我的问题,我不知道具体是什么,但我可能有线索。

我试图在这个文件夹中运行 "D:\Users\user\Documents\Projects\NLW#5\podcastrnext",但没有成功。比我尝试更改到另一个文件夹,这是我使用的文件夹 "D:\Users\user\Documents\Projects\podcastr" 并且这次有效。

我相信问题出在特殊字符“#”上,不知何故程序迷路了。

【讨论】:

帮助我。目录路径上的特殊字符导致此问题。谢谢!【参考方案2】:

我遇到了同样的问题,从项目路径中删除“#”效果很好。

【讨论】:

太棒了!谢谢你帮助我们,路易斯! 为我修好了,谢谢!【参考方案3】:

在文件 next.config.js 中插入 module.exports:

webpack5: 错误

【讨论】:

你是救生员!

以上是关于Next.js 找不到模块 loader.js的主要内容,如果未能解决你的问题,请参考以下文章

Gatsby - 错误:找不到模块 '..\node_modules\gatsby\dist\utils\babel-loader.js'

Next.js:找不到模块:无法解析“canvg”

Next.js '找不到模块'./filename.jpeg'。来不及上传图片

解析错误:找不到模块'next/babel'

错误:在 next.js 中找不到模块“swiper/react”

从 JSON 文件动态加载图像位置 - (找不到模块...) React, Next.js