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

Gatsby应用启动失败:Unexpected template string错误求助

Hey there, let's get that Gatsby dev server running again! That error you're seeing in gatsby-plugin-mdx's gatsby-node.js file almost always boils down to an outdated Node.js version that doesn't support ES6 template string syntax (the `${variable}` style of string interpolation). Newer versions of gatsby-plugin-mdx use this modern syntax, and if your Node version is too old, it throws a fit.

Here's how to fix it step by step:

1. Check Your Current Node.js Version

First, confirm what Node version you're running. Open your terminal and run:

node -v

Gatsby officially recommends Node.js 18.x or later (LTS version is best). If your version is below 14.x, that's almost certainly the culprit here.

2. Upgrade Node.js

How you upgrade depends on how you installed Node:

  • If you use nvm (Node Version Manager, the easiest way to manage multiple Node versions), run these commands:
    nvm install 18  # Installs the latest 18.x LTS version
    nvm use 18       # Switches to use this version
    
  • If you installed Node directly from the official site, go to the official Node.js website and download the latest LTS release, then run the installer.

3. Clean Dependencies and Reinstall

After upgrading Node, it's a good idea to clear out old dependencies to avoid any leftover compatibility issues:

# Delete the node_modules folder and lock files
rm -rf node_modules package-lock.json yarn.lock

# Reinstall all dependencies
npm install
# Or if you use yarn:
# yarn install

4. Test the Fix

Now try starting your Gatsby server again:

gatsby develop

If you still run into issues (unlikely, but just in case), you can lock gatsby-plugin-mdx to an older version that's compatible with your previous Node setup. Edit your package.json to specify:

"gatsby-plugin-mdx": "^3.15.2"

Then run npm install again to install that specific version.

Quick note: Your gatsby-config.js setup looks totally fine—this error has nothing to do with your plugin configuration, it's purely a Node version/plugin compatibility issue.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 06:44:09