node.js npm 前端 后端 webpack 完美地解决Please verify that the package.json has a valid “main“ entry的问题 - 1 dev

📅 2026-11-30 👤 拼多多助力营销技巧 📂 手赚APP 👁️ 228 次阅读

文章目录

1. 复现问题2. 分析问题3. 解决问题4. 总结问题5. 其他解决方案5.1 方案15.2 方案2

1. 复现问题

今天准备克隆Redis桌面(GUI)管理客户端,故按照官方文档给出的指令运行时,如下图所示:

但在执行指令npm start却报出如下图错误:

PS D:\Software\RedisDesktopManager\AnotherRedisDesktopManager>npm start

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> another-redis-desktop-manager@1.1.1 start

> npm run dev

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> another-redis-desktop-manager@1.1.1 dev

> webpack serve --mode development --progress --config build/webpack.dev.conf.js

[webpack-cli] You need to install 'webpack-dev-server' for running 'webpack serve'.

Error: Cannot find module 'D:\Software\RedisDesktopManager\AnotherRedisDesktopManager\node_modules\fs.realpath\index.js'. Please verify that the package.json has a valid "main" entry

即Please verify that the package.json has a valid "main" entry。

2. 分析问题

Please verify that the package.json has a valid "main" entry翻译成中文是请验证 package.json 是否具有有效的“主”条目。

我们打开package.json文件,如下代码所示:

{

"name": "fs.realpath",

"version": "1.0.0",

"description": "Use node's fs.realpath, but fall back to the JS implementation if the native one fails",

"main": "index.js",

"dependencies": {},

"devDependencies": {},

"scripts": {

"test": "tap test/*.js --cov"

},

"repository": {

"type": "git",

"url": "git+https://github.com/isaacs/fs.realpath.git"

},

"keywords": [

"realpath",

"fs",

"polyfill"

],

"author": "Isaac Z. Schlueter(http://blog.izs.me/)",

"license": "ISC",

"files": [

"old.js",

"index.js"

]

}

正如上述代码中的 "main": "index.js",所示,package.json的main入口是正是index.js文件。

我们再看上述错误信息中这句话:Cannot find module 'D:\Software\RedisDesktopManager\AnotherRedisDesktopManager\node_modules\fs.realpath\index.js',即在package.json同目录下没有index.js文件。

换句话说,因为没有index.js文件,导致package.json找不到程序主入口。,如下图所示:

3. 解决问题

既然在package.json同目录下没有index.js文件,我们需要创建一个空的index.js,如下图所示:

创建完成后,重新输入npm start的指令,此时,能够正常执行了,如下图所示: 拼多多帮助力入口

4. 总结问题

Please verify that the package.json has a valid "main" entry这样的错误,一般是没有package.json中的主文件。

因而,我们需要到package.json文件中找到对应的主文件,然后创建该主文件即可。

5. 其他解决方案

如果上述解决方案无法解决你的问题,可以参考如下解决方案。

5.1 方案1

删除项目文件中的package-lock.json文件 运行命令npm install 重新启动项目

5.2 方案2

删除node_modules和package-lock.json这两个文件 命令行输npm i会重新下载包 nodemon xxx.js重新执行检查没有报错

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧