简体   繁体   English

每当我尝试使用 Next.js 运行“npm run dev”时,都找不到错误模块

[英]ERROR MODULE NOT FOUND whenever I try to run 'npm run dev' using Next.js

Whenever I run npm run dev I get this error.每当我运行npm run dev时,我都会收到此错误。

I've tried to delete node_modules and reinstall it using npm install but that didn't work.我尝试删除node_modules并使用npm install重新安装它,但这没有用。 Then I tried to delete both node_modules and package-lock.json and reinstall them, that didn't work.然后我尝试删除node_modulespackage-lock.json并重新安装它们,但没有成功。 I even tried upgrading Node to the latest version, but I'm still getting this issue.我什至尝试将 Node 升级到最新版本,但我仍然遇到这个问题。

I appreciate any help I get.我很感激我得到的任何帮助。 Thank you in advance.先感谢您。

Error: Cannot find module 'C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\postcss\lib\parser'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:952:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:945:15)
    at resolveExports (node:internal/modules/cjs/loader:473:14)
    at Function.Module._findPath (node:internal/modules/cjs/loader:513:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:911:27)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.552 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11590)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735)
    at Object.560 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:400)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735)
    at Object.290 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:260)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735)
    at Object.632 (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:3733)
    at __webpack_require__ (C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\next\dist\compiled\postcss-scss\scss-syntax.js:1:11735) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Users\\jaydev\\Desktop\\ecommerce\\fashionsite\\node_modules\\postcss\\package.json'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fashionsite@0.1.0 dev: `next dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the fashionsite@0.1.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jaydev\AppData\Roaming\npm-cache\_logs\2020-12-25T07_06_40_981Z-debug.log

package.json: { "name": "fashionsite", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start" }, "dependencies": { "next": "10.0.4", "react": "17.0.1", "react-dom": "17.0.1" } } package.json: { "name": "fashionsite", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "next build ”,“开始”:“下一个开始”},“依赖项”:{“下一个”:“10.0.4”,“反应”:“17.0.1”,“react-dom”:“17.0.1”}}

  1. stop your dev server (ctrl+c)停止你的开发服务器 (ctrl+c)
  2. delete .next folder in your project's root folder.删除项目根文件夹中的.next文件夹。
  3. delete node_modules folder and package-lock.json file too.删除node_modules文件夹和package-lock.json文件。
  4. run npm cache clean --force运行npm cache clean --force
  5. run npm install运行npm install
  6. run npm run dev运行npm run dev

If the above didn't work then open your file explorer and see if the specified file exists on the specified path or not: C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\postcss\lib\parser.js如果上述方法不起作用,请打开文件资源管理器并查看指定文件是否存在于指定路径中: C:\Users\jaydev\Desktop\ecommerce\fashionsite\node_modules\postcss\lib\parser.js

if it exists try moving your project's folder to a path other than desktop due to windows permission problems and let me know if the problem is resolved.如果存在 windows 权限问题,请尝试将您的项目文件夹移动到desktop以外的路径,并让我知道问题是否已解决。

How to solve npm error "npm ERR! code ELIFECYCLE" if this isnt gonna help you,let me see what you export on server.js // Try this aswell: https://reactgo.com/npm-err-code-elifecycle/ 如何解决 npm 错误“npm ERR!code ELIFECYCLE”如果这对你没有帮助,让我看看你在 server.js 上导出的内容//试试这个: https://reactgo.com/npm-err-code-elifecycle /

I had a similar issue and found that when I was running npm install after removing node_modules it wasn't correctly installing all the dependencies because my node version had switched back to an older version.我遇到了类似的问题,发现当我在删除node_modules后运行npm install时,它没有正确安装所有依赖项,因为我的节点版本已切换回旧版本。

Make sure your environment is configured correctly first.首先确保您的环境配置正确。 For me: nvm use 16.0.0 and then npm install对我来说: nvm use 16.0.0然后npm install

Also, when you run npm install are there any messages that come up in the command line saying saying a dependency isn't met or something like that, might give you some hints of where to look.此外,当您运行npm install时,是否有任何消息出现在命令行中,说不满足依赖关系或类似的东西,可能会给您一些寻找位置的提示。

move next.config.js file from you project folder then execute npm run dev.从项目文件夹中移动 next.config.js 文件,然后执行 npm 运行开发。

or或者

comment the contents of next.config.js.注释 next.config.js 的内容。

any of the above methods will help run npm run dev.以上任何一种方法都将有助于运行 npm run dev。

make sure u already update/upgrade确保你已经更新/升级

sudo apt update
sudo apt upgrade

after u run this command在你运行这个命令之后

curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash 
sudo apt-get install -y nodejs

sudo apt install npm

use latest node js repo avoid using sudo apt install nodejs..outdated..使用最新的 node js repo 避免使用 sudo apt install nodejs..outdated..

To get rid of this error what you have to do... just update your node.js version Hopefully, it will help you.要摆脱这个错误你必须做什么......只需更新你的 node.js 版本希望它会帮助你。

In my case it turned out to be a problem with windows permissions.在我的情况下,它原来是 windows 权限的问题。 My project was on Desktop and changing its location to a directory with more permissions helped.我的项目在桌面上,将其位置更改为具有更多权限的目录会有所帮助。

Make sure you are in the right directory when using npm run dev.使用 npm 运行开发时,请确保您在正确的目录中。 You can also try switching to yarn.您也可以尝试切换到纱线。

I found this article helpful ->我发现这篇文章很有帮助->

https://hidayatabisena.medium.com/how-to-solve-npm-err-code-elifcycle-when-running-npm-run-dev-on-your-next-js-project-4794226d040f https://hidayatabisena.medium.com/how-to-solve-npm-err-code-elifcycle-when-running-npm-run-dev-on-your-next-js-project-4794226d040f

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Next.js教程,运行Next.js开发服务器出错(npm run dev) - Next.js tutorial, error running Next.js dev server (npm run dev) 我收到路径错误:[找不到模块] 每当我尝试在 VS Code 中运行任何与 npm 相关的命令时 - I got path error : [module not found] whenever I try to run any npm related command in VS Code 我尝试使用 vercel 创建一个 next.js webapp,但是当我尝试在 cmd 上运行 vercel dev 时,它给了我这个错误 - I try to create a next.js webapp with vercel, but when i try to run vercel dev on cmd, it gave me this error NPM 错误,NEXT.JS 错误无法使用 npm run dev - NPM ERROR, NEXT.JS ERROR can not use npm run dev 我无法使用 npm run dev 启动 Next.js 和 tailwind 项目 - I am not able to start Next.js and tailwind project with npm run dev 错误:在 Next 项目上运行 npm run dev 时找不到模块“D:\next\dist\bin\next” - Error: Cannot find module 'D:\next\dist\bin\next' when running npm run dev on a Next project 每当我尝试在 Visual Studio 代码上运行“npm install”时出现错误 - I get an error whenever i try to run "npm install" on visual studio code 我尝试在终端中执行 npm run dev 命令时出现 Npm 错误 - Npm Error while i try to execute npm run dev command in my terminal 每当我尝试通过 Heroku 运行我的服务器时,我都会收到“错误:找不到模块 'dotenv'” - Whenever I try to run my server via Heroku I get "Error: Cannot find module 'dotenv'" 我正在尝试将 NPM package 作为插件注入到 Next.js 应用程序上,以避免出现“找不到模块:无法解析‘child_process’”错误 - I'm Trying to Inject An NPM package As A Plugin on A Next.js App to Avoid A "Module not found: Can't resolve 'child_process'" Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM