3

使用 react-snaps 构建我的 react 项目时出现错误。

我环顾四周,所有错误都与 puppeteer 有关 - 但我没有使用 puppeteer 直接获取那些问题的内容,因此答案不适用。

问题——我认为——是当 react-snap 渲染我的页面时,他们正在对我的服务器进行 API 调用,其中一些失败是因为它们没有经过身份验证或其他原因。但是所有其他问题都表明这与“页面在完成之前退出”有关,我不知道当我运行 react-snap 脚本时这意味着什么?它不像 puppeteer 那样获取页面。(也许是?我不知道,从未使用过 puppeteer)

这是我的脚本:

  "start": "react-scripts start",
    "build": "react-scripts --max_old_space_size=4096 build && npm run build-sw && npm run clean-cra-sw",
    "clean-cra-sw": "rm -f build/precache-manifest.*.js && rm -f build/service-worker.js",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "build-sw": "node ./src/sw-build.js",
    "postbuild": "react-snap"

这是调试日志中的错误"npm run build"

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Spader\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@6.10.2
3 info using node@v10.15.3
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle appv2.0@0.1.0~prebuild: appv2.0@0.1.0
6 info lifecycle appv2.0@0.1.0~build: appv2.0@0.1.0
7 verbose lifecycle appv2.0@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle appv2.0@0.1.0~build: PATH: C:\user...\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\user...\coding\path/to/app\node_modules\.bin;C:\user...\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\user...\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\nodejs;C:\Program Files\Amazon\AWSCLI\bin;C:\Program Files\Git\cmd;C:\Program Files\PuTTY;C:\Program Files\dotnet;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\user...\.windows-build-tools\python27;C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\user...\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\.bin;C:\user...\AppData\Roaming\npm\node_modules\.bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\nodejs;C:\Program Files\Amazon\AWSCLI\bin;C:\Program Files\Git\cmd;C:\user...\AppData\Local\Microsoft\WindowsApps;C:\user...\AppData\Roaming\npm;C:\user...\AppData\Local\Programs\Microsoft VS Code\bin;C:\user...\.dotnet\tools;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle appv2.0@0.1.0~build: CWD: C:\user...\coding\path/to/app
10 silly lifecycle appv2.0@0.1.0~build: Args: [ '/d /s /c',
10 silly lifecycle   'react-scripts --max_old_space_size=4096 build && npm run build-sw && npm run clean-cra-sw' ]
11 silly lifecycle appv2.0@0.1.0~build: Returned: code: 0  signal: null
12 info lifecycle appv2.0@0.1.0~postbuild: appv2.0@0.1.0
13 verbose lifecycle appv2.0@0.1.0~postbuild: unsafe-perm in lifecycle true
14 verbose lifecycle appv2.0@0.1.0~postbuild: PATH: C:\user...\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\user...\coding\path/to/app\node_modules\.bin;C:\user...\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\user...\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\nodejs;C:\Program Files\Amazon\AWSCLI\bin;C:\Program Files\Git\cmd;C:\Program Files\PuTTY;C:\Program Files\dotnet;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\user...\.windows-build-tools\python27;C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\user...\AppData\Roaming\npm\node_modules\windows-build-tools\node_modules\.bin;C:\user...\AppData\Roaming\npm\node_modules\.bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\nodejs;C:\Program Files\Amazon\AWSCLI\bin;C:\Program Files\Git\cmd;C:\user...\AppData\Local\Microsoft\WindowsApps;C:\user...\AppData\Roaming\npm;C:\user...\AppData\Local\Programs\Microsoft VS Code\bin;C:\user...\.dotnet\tools;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
15 verbose lifecycle appv2.0@0.1.0~postbuild: CWD: C:\user...\coding\path/to/app
16 silly lifecycle appv2.0@0.1.0~postbuild: Args: [ '/d /s /c', 'react-snap' ]
17 silly lifecycle appv2.0@0.1.0~postbuild: Returned: code: 1  signal: null
18 info lifecycle appv2.0@0.1.0~postbuild: Failed to exec postbuild script
19 verbose stack Error: appv2.0@0.1.0 postbuild: `react-snap`
19 verbose stack Exit status 1
19 verbose stack     at EventEmitter.<anonymous> (C:\user...\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:326:16)
19 verbose stack     at EventEmitter.emit (events.js:189:13)
19 verbose stack     at ChildProcess.<anonymous> (C:\user...\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
19 verbose stack     at ChildProcess.emit (events.js:189:13)
19 verbose stack     at maybeClose (internal/child_process.js:970:16)
19 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
20 verbose pkgid appv2.0@0.1.0
21 verbose cwd C:\user...\coding\path/to/app
22 verbose Windows_NT 10.0.18362
23 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
24 verbose node v10.15.3
25 verbose npm  v6.10.2
26 error code ELIFECYCLE
27 error errno 1
28 error appv2.0@0.1.0 postbuild: `react-snap`
28 error Exit status 1
29 error Failed at the appv2.0@0.1.0 postbuild script.
29 error This is probably not a problem with npm. There is likely additional logging output above.
30 verbose exit [ 1, true ]

这是构建时控制台中的特定错误

  console.log at /ads_page: %c next state color: #4CAF50; font-weight: bold JSHandle@object
  console.log at /ads_page: console.groupEnd
  console.log at /ads_page: { total: { value: 0, relation: 'eq' },
  max_score: null,
  hits: [] }
  console.log at /404.html: %c action %cFETCH_ADS_SUCCESS %c@ 11:22:01.228 color: gray; font-weight: lighter; color: inherit; color: gray; font-weight: lighter;
  console.log at /404.html: %c prev state color: #9E9E9E; font-weight: bold JSHandle@object
  console.log at /404.html: %c action     color: #03A9F4; font-weight: bold JSHandle@object
  console.log at /404.html: %c next state color: #4CAF50; font-weight: bold JSHandle@object
  console.log at /404.html: console.groupEnd
  console.log at /404.html: { total: { value: 0, relation: 'eq' },
  max_score: null,
  hits: [] }
  UnhandledPromiseRejectionWarning { Error: Protocol error (Network.getResponseBody): Target closed.
    at Promise (C:\path\to\app\node_modules\puppeteer\lib\Connection.js:183:56)
    at new Promise (<anonymous>)
    at CDPSession.send (C:\path\to\app\node_modules\puppeteer\lib\Connection.js:182:12)
    at _contentPromise._bodyLoadedPromise.then (C:\path\to\app\node_modules\puppeteer\lib\NetworkManager.js:612:45)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  -- ASYNC --
    at Response.<anonymous> (C:\path\to\app\node_modules\puppeteer\lib\helper.js:111:15)
    at Page.page.on.response (C:\path\to\app\node_modules\minimalcss\src\run.js:264:20)
    at Page.emit (events.js:189:13)
    at NetworkManager.Page.networkManager.on.event (C:\path\to\app\node_modules\puppeteer\lib\Page.js:111:69)
    at NetworkManager.emit (events.js:189:13)
    at NetworkManager._onResponseReceived (C:\path\to\app\node_modules\puppeteer\lib\NetworkManager.js:272:10)
    at CDPSession.emit (events.js:189:13)
    at CDPSession._onMessage (C:\path\to\app\node_modules\puppeteer\lib\Connection.js:200:12)
    at Connection._onMessage (C:\path\to\app\node_modules\puppeteer\lib\Connection.js:112:17)
    at WebSocketTransport._ws.addEventListener.event (C:\path\to\app\node_modules\puppeteer\lib\WebSocketTransport.js:44:24)
  message: 'Protocol error (Network.getResponseBody): Target closed.' }

您可以看到它从“FETCH_ADS_SUCCESS”中获取广告的完成,但随后它会抛出此错误。

还有为什么它说页面是404.html- 当没有 404 页面并且它只是在ads_page

4

0 回答 0