[英]Node.js Cannot Find Module error on 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
文件在同一行。
啟動腳本引用index.js
,但您沒有這樣的文件 - 它位於src/index.js
下。 您可以將其移動到項目根目錄,或相應地更新start
腳本:
"scripts": {
"start": "node src/index.js"
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.