我可以正常运行以下命令而没有错误:npm start
,npm run build
和pm2 start server.js
。但是,当我尝试在Netlify上部署项目时,我在Chrome控制台中收到以下错误:未捕获的SyntaxError:无效或意外的令牌,返回的页面为空白,并且在Netlify构建日志。我不知道为什么会这样或如何解决。请尽快帮助我。
server.js:
const express = require("express");
const path = require("path");
const app = express();
const port = 4000;
const root = require("path").join(__dirname, "build");
app.use(express.static(root));
app.get("*", (req, res) => {
res.sendFile("index.html", { root });
});
app.listen(port, () => console.log(`Running on port ${port}`));
package.json:
{
"name": "project",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"jw-react-pagination": "^1.1.0",
"react": "^16.9.0",
"react-bootstrap": "^1.3.0",
"react-dom": "^16.9.0",
"react-player": "^1.13.0",
"react-router-dom": "^5.0.1",
"react-scripts": "^3.4.3",
"reactstrap": "^8.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
错误消息:
netlify:构建日志:
10:53:05 AM: Build ready to start
10:53:08 AM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
10:53:08 AM: build-image tag: v3.4.1
10:53:08 AM: buildbot version: 648208d76731cd5bca75c1e9bc99d2032a1f1473
10:53:08 AM: Fetching cached dependencies
10:53:08 AM: Starting to download cache of 140.6MB
10:53:08 AM: Finished downloading cache in 807.309358ms
10:53:08 AM: Starting to extract cache
10:53:15 AM: Finished extracting cache in 6.082087117s
10:53:15 AM: Finished fetching cache in 7.016759665s
10:53:15 AM: Starting to prepare the repo for build
10:53:15 AM: Preparing Git Reference refs/heads/master
10:53:18 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'build' versus 'build/' in the Netlify UI
10:53:18 AM: Starting build script
10:53:18 AM: Installing dependencies
10:53:18 AM: Python version set to 2.7
10:53:19 AM: Started restoring cached node version
10:53:22 AM: Finished restoring cached node version
10:53:23 AM: v12.18.0 is already installed.
10:53:24 AM: Now using node v12.18.0 (npm v6.14.4)
10:53:24 AM: Started restoring cached build plugins
10:53:24 AM: Finished restoring cached build plugins
10:53:24 AM: Attempting ruby version 2.7.1, read from environment
10:53:26 AM: Using ruby version 2.7.1
10:53:26 AM: Using PHP version 5.6
10:53:26 AM: 5.2 is already installed.
10:53:26 AM: Using Swift version 5.2
10:53:26 AM: Started restoring cached node modules
10:53:26 AM: Finished restoring cached node modules
10:53:27 AM: Started restoring cached go cache
10:53:27 AM: Finished restoring cached go cache
10:53:27 AM: go version go1.14.4 linux/amd64
10:53:27 AM: go version go1.14.4 linux/amd64
10:53:27 AM: Installing missing commands
10:53:27 AM: Verify run directory
10:53:28 AM:
10:53:28 AM: ┌─────────────────────────────┐
10:53:28 AM: │ Netlify Build │
10:53:28 AM: └─────────────────────────────┘
10:53:28 AM:
10:53:28 AM: ❯ Version
10:53:28 AM: @netlify/build 4.0.4
10:53:28 AM:
10:53:28 AM: ❯ Flags
10:53:28 AM: deployId: 5f6c2d1e14a2c400079aabfa
10:53:28 AM: mode: buildbot
10:53:28 AM:
10:53:28 AM: ❯ Current directory
10:53:28 AM: /opt/build/repo
10:53:28 AM:
10:53:28 AM: ❯ Config file
10:53:28 AM: No config file was defined: using default values.
10:53:28 AM:
10:53:28 AM: ❯ Context
10:53:28 AM: production
10:53:28 AM:
10:53:28 AM: ┌───────────────────────────────────┐
10:53:28 AM: │ 1. Build command from Netlify app │
10:53:28 AM: └───────────────────────────────────┘
10:53:28 AM:
10:53:28 AM: $ npm run build
10:53:28 AM: > project@0.1.0 build /opt/build/repo
10:53:28 AM: > react-scripts build
10:53:30 AM: Creating an optimized production build...
10:53:38 AM: Compiled successfully.
10:53:38 AM:
10:53:38 AM: File sizes after gzip:
10:53:39 AM: 3.99 MB build/static/js/main.32349faf.chunk.js
10:53:39 AM: 49.51 KB build/static/js/2.0e21026f.chunk.js
10:53:39 AM: 2.65 KB build/static/css/main.6ddef2a7.chunk.css
10:53:39 AM: 769 B build/static/js/runtime-main.f16ea130.js
10:53:39 AM: The project was built assuming it is hosted at /.
10:53:39 AM: You can control this with the homepage field in your package.json.
10:53:39 AM: The build folder is ready to be deployed.
10:53:39 AM: You may serve it with a static server:
10:53:39 AM: npm install -g serve
10:53:39 AM: serve -s build
10:53:39 AM: Find out more about deployment here:
10:53:39 AM: bit.ly/CRA-deploy
10:53:39 AM:
10:53:39 AM: (build.command completed in 11.3s)
10:53:39 AM:
10:53:39 AM: ┌─────────────────────────────┐
10:53:39 AM: │ Netlify Build Complete │
10:53:39 AM: └─────────────────────────────┘
10:53:39 AM:
10:53:39 AM: (Netlify Build completed in 11.3s)
10:53:40 AM: Caching artifacts
10:53:40 AM: Started saving node modules
10:53:40 AM: Finished saving node modules
10:53:40 AM: Started saving build plugins
10:53:40 AM: Finished saving build plugins
10:53:40 AM: Started saving pip cache
10:53:40 AM: Finished saving pip cache
10:53:40 AM: Started saving emacs cask dependencies
10:53:40 AM: Finished saving emacs cask dependencies
10:53:40 AM: Started saving maven dependencies
10:53:40 AM: Finished saving maven dependencies
10:53:40 AM: Started saving boot dependencies
10:53:40 AM: Finished saving boot dependencies
10:53:40 AM: Started saving go dependencies
10:53:40 AM: Finished saving go dependencies
10:53:40 AM: Build script success
10:53:40 AM: Starting to deploy site from 'build'
10:53:40 AM: Creating deploy tree
10:53:40 AM: Creating deploy upload records
10:53:40 AM: 0 new files to upload
10:53:40 AM: 0 new functions to upload
10:53:40 AM: Starting post processing
10:53:40 AM: Post processing - HTML
10:53:40 AM: Post processing - header rules
10:53:40 AM: Post processing - redirect rules
10:53:40 AM: Post processing done
10:53:40 AM: Site is live
10:54:04 AM: Finished processing build request in 56.875804209s
cmd:npm运行构建
C:\Users\prash\Desktop\site>npm run build
> project@0.1.0 build C:\Users\prash\Desktop\site
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
3.99 MB build\static\js\main.bd1fe936.chunk.js
49.51 KB build\static\js\2.0e21026f.chunk.js
2.65 KB build\static\css\main.6ddef2a7.chunk.css
769 B build\static\js\runtime-main.f16ea130.js
The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
You may serve it with a static server:
serve -s build
Find out more about deployment here:
bit.ly/CRA-deploy
C:\Users\prash\Desktop\site>pm2 start server.js
[PM2] Applying action restartProcessId on app [server](ids: [ 0 ])
[PM2] [server](0) ✓
[PM2] Process successfully started
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ server │ default │ 0.1.0 │ fork │ 8572 │ 0s │ 2 │ online │ 0% │ 33.1mb │ prash │ disabled │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
答案 0 :(得分:0)
您的console.log需要``
http://host:port/solr/collection_name/update?commit=true&stream.body=<delete><query>*:*</query></delete>