使用create-react-app构建后执行serve -s build报async语法错误求助
serve -s build The error you're hitting stems from an outdated Node.js version that doesn't support the async/await syntax natively. Async/await is an ES2017 feature introduced in Node.js 7.6.0—your current Node version is too old to parse this syntax, which is why the serve tool (which uses async/await in its code) is throwing an error, even though your React app was correctly transpiled by create-react-app.
Here are two reliable fixes:
Solution 1: Upgrade Node.js (Recommended)
Older Node.js versions are no longer maintained and pose security risks, so upgrading is the best long-term fix. Use Node Version Manager (nvm) to easily switch to a supported version:
- Install nvm if you haven't already (it's a tool that lets you manage multiple Node versions on your machine).
- Run
nvm install --ltsto install the latest Long-Term Support (LTS) version of Node.js. - Switch to this version with
nvm use --lts. - Verify your version with
node -v—you should see a number likev18.xorv20.x(current LTS releases).
Once upgraded, re-run serve -s build and the error should be gone.
Solution 2: Install an Older Compatible serve Version
If upgrading Node.js isn't feasible right now, install an older version of serve that doesn't rely on async/await. Version 11.x works with Node versions as low as 6.x:
- Uninstall your current global
serveinstance:npm uninstall -g serve - Install version 11:
npm install -g serve@11 - Run
serve -s buildagain—this should resolve the syntax error.
Note: Using an older serve version means missing out on latest features and security patches, so prioritize upgrading Node.js when possible.
内容的提问来源于stack exchange,提问作者Piotr G

