繁体   English   中英

npm 启动时出现“webpack 编译时出现 1 个错误”

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM