【问题标题】:Node error, can't set up localhost to test React applications **SOLVED** .env file节点错误,无法设置 localhost 来测试 React 应用程序**已解决** .env 文件
【发布时间】:2020-05-26 17:22:24
【问题描述】:

我在尝试运行任何 React 应用程序时遇到了一个真正的问题,我的节点总是抛出错误。我的目标是将此项目设置为 localhost:8000 以便我可以对其进行测试。

这是我的 package.json。

{
  "name": "cr-surf-forecast",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "bootstrap": "^4.3.1",
    "node-sass": "^4.14.1",
    "react": "^16.8.3",
    "react-dom": "^16.8.3",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.5",
    "styled-components": "^4.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

我已经删除了 .lock 并尝试重新安装依赖项,同样的错误,我会重复。我现在正在擦除 node_mudules 文件夹并执行 npm install & npm start。 npm install 没有错误,但是一旦我尝试 npm start,就会发生错误,如下所示。

run `npm audit fix` to fix them, or `npm audit` for details
PS C:\Users\Dev\Desktop\surf-forecasting-app-master> npm start

> cr-surf-forecast@0.1.0 start C:\Users\Dev\Desktop\surf-forecasting-app-master
> react-scripts start

'react-scripts' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.

[ED. TRANSLATION: 'react-scripts' is not recognized as an internal
command or external, an operable program or a batch file.]

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cr-surf-forecast@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cr-surf-forecast@0.1.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\Dev\AppData\Roaming\npm-cache\_logs\2020-05-26T17_09_00_453Z-debug.log
PS C:\Users\Dev\Desktop\surf-forecasting-app-master>

这是我运行 npm start 时创建的错误日志:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Dev\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.5
3 info using node@v12.16.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle cr-surf-forecast@0.1.0~prestart: cr-surf-forecast@0.1.0
6 info lifecycle cr-surf-forecast@0.1.0~start: cr-surf-forecast@0.1.0
7 verbose lifecycle cr-surf-forecast@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle cr-surf-forecast@0.1.0~start: PATH: C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Dev\Desktop\surf-forecasting-app-master\node_modules\.bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python38\Scripts\;C:\Python38\;C:\Program Files (x86)\Intel\TXE Components\iCLS\;C:\Program Files\Intel\TXE Components\iCLS\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\TXE Components\DAL\;C:\Program Files (x86)\Intel\TXE Components\DAL\;C:\Program Files\Intel\TXE Components\IPT\;C:\Program Files (x86)\Intel\TXE Components\IPT\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\dotnet\;C:\Program Files (x86)\dotnet\;C:\Users\Dev\AppData\Local\Microsoft\WindowsApps;;C:\Users\Dev\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Dev\AppData\Roaming\npm
9 verbose lifecycle cr-surf-forecast@0.1.0~start: CWD: C:\Users\Dev\Desktop\surf-forecasting-app-master
10 silly lifecycle cr-surf-forecast@0.1.0~start: Args: [ '/d /s /c', 'react-scripts start' ]
11 silly lifecycle cr-surf-forecast@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle cr-surf-forecast@0.1.0~start: Failed to exec start script
13 verbose stack Error: cr-surf-forecast@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:310:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Dev\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:310:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid cr-surf-forecast@0.1.0
15 verbose cwd C:\Users\Dev\Desktop\surf-forecasting-app-master
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Dev\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.16.3
19 verbose npm  v6.14.5
20 error code ELIFECYCLE
21 error errno 1
22 error cr-surf-forecast@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the cr-surf-forecast@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

我迷路了,我看到 node.js 曾经与一个巨大的项目(1gb 的 node_modules)一起工作,但我开始认为这是一个计算机问题,我使用的是带有 Windows 10 家庭版的三星闪存笔记本电脑,你能伙计们帮帮我?感谢您的关注。

【问题讨论】:

    标签: javascript node.js localhost


    【解决方案1】:

    已修复 ***

    遇到相同问题的每个人都应该尝试:

    解决我的问题的是最后一个:将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件

    o fix the dependency tree, try following the steps below in the exact order:
    
      1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
      2. Delete node_modules in your project folder.
      3. Remove "webpack-dev-server" from dependencies and/or devDependencies in the package.json file in your project folder.
      4. Run npm install or yarn, depending on the package manager you use.
    
    In most cases, this should be enough to fix the problem.
    If this has not helped, there are a few other things you can try:
    
      5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
         This may help because npm has known issues with package hoisting which may get resolved in future versions.
    
      6. Check if c:\Users\Dev\node_modules\webpack-dev-server is outside your project directory.
         For example, you might have accidentally installed something in your home folder.
    
      7. Try running npm ls webpack-dev-server in your project folder.
         This will tell you which other package (apart from the expected react-scripts) installed webpack-dev-server.
    
    If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
    That would permanently disable this preflight check in case you want to proceed anyway.
    
    P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
    
    PS C:\Users\Dev\Desktop\surf-forecasting-app-master> node c:\Users\Dev\Desktop\surf-forecasting-app-master\node_modules\react-scripts\scripts\start.js
    Starting the development server...
    Compiled with warnings.

    OK 本地主机:8000 完成

    【讨论】:

      猜你喜欢
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      相关资源
      最近更新 更多