我刚刚安装了node js并创建了一个react应用程序,当我试图执行npm start时,我在终端中得到了'webpack compiled with 1 error'。
我真的没有做任何单一的事情或在应用程序的变化。
我的终端就是这个样子
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"
]
}
}
请告诉我为什么我得到这个错误,以及如何解决这个问题。
3条答案
按热度按时间az31mfrm1#
由于某种原因,
react-scripts
找不到webpack-dev-server
。您可以尝试删除node_modules
并重新运行npm install
wgeznvg72#
我注意到在父文件夹的名称中有空格,即
\Tech\Node js\React js\Projects\Project 1\project1
。我只是删除了空格并重新命名了父文件夹,现在它看起来像这个\Tech\Nodejs\Reactjs\Projects\Project1\project1
,现在对我来说工作正常。sbtkgmzw3#
进入终端并输入以下代码: