Yarn SyntaxError: Missing ) After Argument List

5 replies
Last updated: Jul 9, 2022
Heyo everyone, does anyone know why I would be getting this error when I am using yarn with the latest preview version?I have been seeing around that people are getting this with pnpm and having it work with npm / yarn, but for me that's not the case.


E:\Projects\test\node_modules\sanity\node_modules\.bin\sanity:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at Object.compileFunction (node:vm:353:18)
    at wrapSafe (node:internal/modules/cjs/loader:1040:15)
    at Module._compile (node:internal/modules/cjs/loader:1076:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:834:12)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (E:\Projects\test\node_modules\sanity\bin\sanity:10:3)
    at Module._compile (node:internal/modules/cjs/loader:1112:14)
AI Update

This is a Windows-specific issue where Node.js is trying to execute a Unix shell script directly. The error happens because the .bin/sanity file in your node_modules contains bash syntax (basedir=$(dirname...)) that Node.js can't parse on Windows.

This is actually a broader Node.js/npm ecosystem issue on Windows where the wrong executable wrapper gets invoked. When you run yarn sanity dev (or any sanity command), yarn should be using the Windows-compatible .cmd wrapper file, but instead it's trying to execute the Unix shell script, which causes Node.js to choke on the bash syntax.

Potential solutions to try:

  1. Use the .cmd extension explicitly in your package.json scripts:

    {
      "scripts": {
        "dev": "sanity.cmd dev",
        "build": "sanity.cmd build"
      }
    }
  2. Run commands with the .cmd extension directly in your terminal:

    yarn sanity.cmd dev
  3. Switch to npm for this project, as some users have reported this being a yarn-specific path resolution issue on Windows. Delete your node_modules and yarn.lock, then:

    npm install
    npm run dev
  4. Check your Node.js version - Make sure you're on a recent LTS version (Node 20+ is required for Sanity Studio v4 according to the breaking changes documentation). Sometimes path resolution issues in .bin wrappers can be version-specific.

  5. Try running the command through npx as an alternative:

    npx sanity dev
  6. Clear and reinstall - Sometimes the .bin wrappers get corrupted during installation:

    rm -rf node_modules
    rm yarn.lock
    yarn install

The fact that you're seeing this with the latest preview version and with yarn specifically (when others report it working with yarn) suggests this might be an edge case in how the CLI binaries are being generated for Windows in that preview build. If none of these solutions work, I'd recommend reporting this on the Sanity GitHub repository with your exact Node.js version, yarn version, and Windows version so the team can investigate the preview build's Windows compatibility.

Haven't seen that yet with yarn. Can you please log the issue on GitHub? Thanks! πŸ™Œ
Thanks for the speedy response, I put the issue up on github :)
Which operating system do you use? πŸ™‚
I use Windows 10

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?