![](/img/trans.png)
[英]NPM - Getting error when trying to run the npm install command (webpack and babel-loader)
[英]Getting 'webpack compiled with 1 error' when npm starts
當我嘗試執行 npm start 時,我剛剛安裝了節點 js 並創建了一個反應應用程序,我在終端中得到了“webpack 編譯時出現 1 個錯誤”。
我真的沒有在應用程序中做任何單一的事情或更改。
這就是我的終端的樣子
PS D:\#D\Tech\Node js\React js\Projects\Project 1> npm -v
8.5.5
PS D:\#D\Tech\Node js\React js\Projects\Project 1> npm create-react-app project1
Unknown command: "create-react-app"
To see a list of supported npm commands, run:
npm help
PS D:\#D\Tech\Node js\React js\Projects\Project 1> npx create-react-app project1
Creating a new React app in D:\#D\Tech\Node js\React js\Projects\Project 1\project1.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...
added 1376 packages in 3m
179 packages are looking for funding
run `npm fund` for details
Initialized a git repository.
Installing template dependencies using npm...
npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
added 39 packages in 18s
179 packages are looking for funding
run `npm fund` for details
Removing template package using npm...
removed 1 package, and audited 1415 packages in 10s
179 packages are looking for funding
run `npm fund` for details
6 moderate severity vulnerabilities
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
Created git commit.
Success! Created project1 at D:\#D\Tech\Node js\React js\Projects\Project 1\project1
Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd project1
npm start
Happy hacking!
PS D:\#D\Tech\Node js\React js\Projects\Project 1> npm start
Failed to compile.
Module not found: Error: Can't resolve 'D:\#D\Tech\Node js\React js\Projects\Project 1\project1\node_modules\webpack-dev-server\client\index.js?protocol=ws%3A&hostname=0.0.0.0&port=3000&pathname=%2Fws&logging=none&reconnect=10' in 'D:\#D\Tech\Node js\React js\Projects\Project 1\project1'ERROR in Module not found: Error: Can't resolve 'D:\#D\Tech\Node js\React js\Projects\Project 1\project1\node_modules\webpack-dev-server\client\index.js?protocol=ws%3A&hostname=0.0.0.0&port=3000&pathname=%2Fws&logging=none&reconnect=10' in 'D:\#D\Tech\Node js\React js\Projects\Project 1\project1'
webpack compiled with 1 error
我的 package.json 是
{
"name": "project1",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
請告訴我為什么會收到此錯誤以及如何解決此問題。
由於某種原因, react-scripts
找不到webpack-dev-server
。 您可以嘗試刪除node_modules
並再次運行npm install
我注意到父文件夾的名稱中有空格,即\Tech\Node js\React js\Projects\Project 1\project1
。 我只是刪除了空格並重命名了父文件夾,現在它看起來像這樣\Tech\Nodejs\Reactjs\Projects\Project1\project1
並且它現在對我來說工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.