You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Starter Kit在OSX出现Unexpected token export报错求助

Why You're Seeing SyntaxError: Unexpected token export on macOS for React Starter Kit

Hey fellow dev, let's break down why this error is popping up on your Mac but not Windows. This issue almost always ties to differences in how Node.js handles ES modules or environment inconsistencies between the two systems. Here are the most likely causes:

  • Mismatched Node.js versions
    Older Node.js versions (pre-v13.2) don’t support ES module syntax like export by default in .js files without extra configuration. It’s possible your Windows machine runs a newer Node version that handles this natively, while your Mac has an outdated release. Check your Node version on both systems with:

    node -v
    

    If your Mac’s version is behind, upgrade it to the latest LTS release—this often fixes the problem right away.

  • Missing ES module configuration in package.json
    The React Starter Kit may rely on Node recognizing .js files as ES modules. For Node versions <v18 (even some newer ones if unconfigured), you need to add "type": "module" to your project’s package.json to tell Node to treat .js files as ES modules instead of CommonJS. If this line is missing or wasn’t properly set up on your Mac, Node will throw that export syntax error.

  • Incomplete or corrupted dependencies
    When moving projects between operating systems, dependencies sometimes install incorrectly—especially transpilation tools (like Babel) that convert ES modules to code Node can understand. Try wiping your existing dependencies and reinstalling fresh:

    rm -rf node_modules package-lock.json
    npm install
    

    This ensures you get OS-specific, uncorrupted builds of all required packages.

  • Directly running the script instead of using npm/yarn commands
    If you’re executing node tools/run.js directly on your Mac, you’re probably skipping the transpilation step that the project’s npm scripts handle. The starter kit’s package.json likely includes a script (like npm start) that uses tools such as babel-node to convert ES module syntax before running the file. Always use the project’s official npm/yarn commands instead of running Node directly on individual files.

内容的提问来源于stack exchange,提问作者Keslavi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:35:07