我有一个使用create-react-app构建的应用程序,正在尝试将其部署在Vercel(Zeit.co)上。我在那里运行了几个类似的应用程序。但是,在构建此应用程序时,npm会在index.js的第一个字符上引发语法错误。
这是我的index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App/>,document.getElementById('root'));
这是构建日志:
00:11:16.204 Retrieving list of deployment files...
00:11:16.371 Downloading 95 deployment files...
00:11:25.145 Installing build runtime...
00:11:25.526 Build runtime installed: 381.250ms
00:11:25.865 Looking up build cache...
00:11:25.898 Build cache not found
00:11:26.236 Installing dependencies...
00:11:46.307 > node-sass@4.14.1 install /vercel/55fcab5f/node_modules/node-sass
00:11:46.307 > node scripts/install.js
00:11:46.585 Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-x64-72_binding.node
00:11:47.521 Download complete
00:11:47.525 Binary saved to /vercel/55fcab5f/node_modules/node-sass/vendor/linux-x64-72/binding.node
00:11:47.558 Caching binary to /vercel/.npm/node-sass/4.14.1/linux-x64-72_binding.node
00:11:47.729 > core-js@2.6.11 postinstall /vercel/55fcab5f/node_modules/babel-runtime/node_modules/core-js
00:11:47.730 > node -e "try{require('./postinstall')}catch(e){}"
00:11:47.801 [96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
00:11:47.801 [96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
00:11:47.801 [96m>[94m https://opencollective.com/core-js [0m
00:11:47.802 [96m>[94m https://www.patreon.com/zloirock [0m
00:11:47.802 [96mAlso,the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
00:11:47.846 > core-js@3.6.5 postinstall /vercel/55fcab5f/node_modules/core-js
00:11:47.846 > node -e "try{require('./postinstall')}catch(e){}"
00:11:47.904 > core-js-pure@3.6.5 postinstall /vercel/55fcab5f/node_modules/core-js-pure
00:11:47.904 > node -e "try{require('./postinstall')}catch(e){}"
00:11:48.331 > node-sass@4.14.1 postinstall /vercel/55fcab5f/node_modules/node-sass
00:11:48.331 > node scripts/build.js
00:11:48.482 Binary found at /vercel/55fcab5f/node_modules/node-sass/vendor/linux-x64-72/binding.node
00:11:48.482 Testing binary
00:11:48.581 Binary is fine
00:11:49.771 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
00:11:49.772 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
00:11:49.772 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack/node_modules/fsevents):
00:11:49.772 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"x64"})
00:11:49.772 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/jest-haste-map/node_modules/fsevents):
00:11:49.772 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"x64"})
00:11:49.772 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
00:11:49.772 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"x64"})
00:11:49.776 added 1751 packages from 838 contributors in 23.147s
00:11:50.745 59 packages are looking for funding
00:11:50.745 run `npm fund` for details
00:11:50.976 Running "npm run build"
00:11:51.179 > template@0.1.0 build /vercel/55fcab5f
00:11:51.179 > react-scripts build
00:11:52.003 Creating an optimized production build...
00:11:53.120 Failed to compile.
00:11:53.120 ./src/index.js
00:11:53.120 Syntax error: Unexpected character '' (1:1)
00:11:53.120 > 1 |
00:11:53.120 | ^
00:11:53.130 npm ERR! code ELIFECYCLE
00:11:53.130 npm ERR! errno 1
00:11:53.131 npm ERR! template@0.1.0 build: `react-scripts build`
00:11:53.131 npm ERR! Exit status 1
00:11:53.131 npm ERR!
00:11:53.131 npm ERR! Failed at the template@0.1.0 build script.
00:11:53.131 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
00:11:53.151 npm ERR! A complete log of this run can be found in:
00:11:53.151 npm ERR! /vercel/.npm/_logs/2020-05-19T22_11_53_132Z-debug.log
00:11:53.156 Error: Command "npm run build" exited with 1
00:11:55.049 Done with "package.json"
问题部分:
00:11:52.003 Creating an optimized production build...
00:11:53.120 Failed to compile.
00:11:53.120 ./src/index.js
00:11:53.120 Syntax error: Unexpected character '' (1:1)
00:11:53.120 > 1 |
00:11:53.120 | ^
该项目使用以下软件包:
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.28","@fortawesome/free-solid-svg-icons": "^5.13.0","@fortawesome/react-fontawesome": "^0.1.9","@testing-library/jest-dom": "^4.2.4","@testing-library/react": "^9.5.0","@testing-library/user-event": "^7.2.1","js-cookie": "^2.2.1","lorem-ipsum": "^2.0.3","merge-images": "^2.0.0","node-sass": "^4.13.1","react": "^16.13.1","react-dom": "^16.13.1","react-icons": "^3.9.0","react-lorem-ipsum": "^1.4.4","react-redux": "^7.2.0","react-router": "^5.1.2","react-router-dom": "^5.1.2","react-router-scroll-top": "^0.2.1","react-scripts": "3.4.1","redux": "^4.0.5","redux-persist": "^6.0.0","redux-thunk": "^2.3.0","xss": "^1.0.6"
},
该应用程序在我的PC上运行正常。 有谁知道如何解决这个问题?