在 npm 启动时获取"webpack 编译为 1 个错误"



我刚刚安装了node js并创建了一个react应用程序,当我尝试执行npm start时,在终端中出现了'webpack编译with 1 error'。

我真的没有做任何单一的事情或改变应用程序。

我的终端是这样的

PS D:#DTechNode jsReact jsProjectsProject 1> npm -v
8.5.5
PS D:#DTechNode jsReact jsProjectsProject 1> npm create-react-app project1
Unknown command: "create-react-app"
To see a list of supported npm commands, run:
npm help
PS D:#DTechNode jsReact jsProjectsProject 1> npx create-react-app project1
Creating a new React app in D:#DTechNode jsReact jsProjectsProject 1project1.
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:#DTechNode jsReact jsProjectsProject 1project1
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:#DTechNode jsReact jsProjectsProject 1> npm start
Failed to compile.
Module not found: Error: Can't resolve 'D:#DTechNode jsReact jsProjectsProject 1project1node_moduleswebpack-dev-serverclientindex.js?protocol=ws%3A&hostname=0.0.0.0&port=3000&pathname=%2Fws&logging=none&reconnect=10' in 'D:#DTechNode jsReact jsProjectsProject 1project1'ERROR in Module not found: Error: Can't resolve 'D:#DTechNode jsReact jsProjectsProject 1project1node_moduleswebpack-dev-serverclientindex.js?protocol=ws%3A&hostname=0.0.0.0&port=3000&pathname=%2Fws&logging=none&reconnect=10' in 'D:#DTechNode jsReact jsProjectsProject 1project1'
webpack compiled with 1 error

我的包。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

我注意到父文件夹的名称中有空格,即TechNode jsReact jsProjectsProject 1project1。我只是删除了空格并重命名父文件夹,现在看起来是这样的TechNodejsReactjsProjectsProject1project1和它现在工作良好的我。

进入终端,输入以下代码:

npx create-react-app project 1
cd project 1
npm start

重命名父文件夹,只是删除了空格

相关内容

最新更新