node.js - Node.js 在 npm start 上找不到模块错误
问题描述
当我运行npm start
命令为我的第一个反应项目启动服务器时,出现如下错误。我尝试卸载并重新安装 node.js,但没有成功。我该如何解决这个问题?我package.json
在这里包括我和我的目录结构。
这是错误:
> reactproject1@1.0.0 start C:\Users\LENOVO\reactproject1
> node index.js
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'C:\Users\LENOVO\reactproject1\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactproject1@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactproject1@1.0.0 start 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\LENOVO\AppData\Roaming\npm-cache\_logs\2020-07-18T09_12_04_972Z-debug.log
这是我package.json
的反应项目文件。我已经通过添加来编辑它"start":"node index.js"
。
{
"name": "reactproject1",
"version": "1.0.0",
"description": "restropart",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
}
我的目录树如下
-ReactProject
-node_modules
-public
-src
->index.js
-package.json
-package-lock.json
我的index.js
文件位于src
文件夹内。、node_modules
、public
和文件位于同一src
行package.json
。package-lock.json
解决方案
The start script refers to index.js
, but you don't have such a file - it's under src/index.js
. You could either move it to the project root, or update the start
script accordingly:
"scripts": {
"start": "node src/index.js"
},
推荐阅读
- excel - 工作表中多个表上的 Selection.Entirerow.Delete 上的运行时错误 1004“应用程序定义或对象定义”
- php - 单页上存在多个谷歌图表的问题 - 标签仅与第一个图表一起显示
- amazon-s3 - AWS api 调用可以取消吗?
- java - 在 Java 中模拟内存屏障以消除易失性读取
- ios - 如何在 iOS 13 中使用自定义颜色支持深色模式启动屏幕?
- ios - 如何使用 URL Scheme 在 iOS 13 中修复“分享到 Instagram 故事”
- qt - QtQuick:用Elide调整两个文本字段的大小
- c# - 尝试将对象的属性放入记录器 NLog 时出错
- linux - 归档 Shell 脚本
- javascript - 如何将 React Context API 与 redux 一起使用?