question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Syntax error in parsing package.json run scripts with env variable using ' prefixed

See original GitHub issue

via @duncanhealy here

Bug description

package.json scripts fail to run if they have environment variables prefixed to the command that use single ticks '

Command

yarn start
yarn build

What is the current behavior?

yarn 1.x parses package.json correctly yarn 2.0.0-rc.27 parses package.json and fails with a syntax error below

Syntax Error: Expected "\\" or [^'] but "'" found (line 1, column 8).
    at Xe (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:36:319549)
    at Object.parse (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:36:328727)
    at Object.t.parseShell (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:36:314751)
    at Object.t.execute (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:24:16165)
    at B.r.configuration.reduceHook.script (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:24:5026)
    at Object.B [as executePackageScript] (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:24:5159)
    at async c.execute (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:58:43949)
    at async c.validateAndExecute (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:24:40434)
    at async c.run (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:36:533800)
    at async s.execute (/home/username/.nvm/versions/node/v12.14.1/lib/node_modules/yarn/bin/yarn.js:58:17806)

What is the expected behavior?

yarn start, build … should parse and run scripts set by scripts block in package.json

Steps to Reproduce

package.json file --> set DEBUG variable to empty / -babel

  "scripts": {
    "start": "DEBUG='-babel' BROWSER=none react-scripts start",
    "build": "DEBUG='' react-scripts build"
}

Workaround

change single ticks ' to \" in scripts

Environment

  • Node Version: 12.14.1
  • Yarn v2 Version: 2.0.0-rc.27
  • OS and version:

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
fleckcommented, Feb 3, 2020

I’m having a similar package.json parsing issue: trying to run this script "temp": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} webpack", results in

yarn temp
Syntax Error: Expected "$", "$(", "${", "&&", "'", ";", "<", "<<<", ">", ">>", "\"", "\\", "|", "|&", "||", [ \t], or end of input but "{" found (line 1, column 36).
    at Xe (/usr/local/lib/node_modules/yarn/bin/yarn.js:36:319549)
    at Object.parse (/usr/local/lib/node_modules/yarn/bin/yarn.js:36:328727)
    at Object.t.parseShell (/usr/local/lib/node_modules/yarn/bin/yarn.js:36:314751)
    at Object.t.execute (/usr/local/lib/node_modules/yarn/bin/yarn.js:24:16165)
    at B.r.configuration.reduceHook.script (/usr/local/lib/node_modules/yarn/bin/yarn.js:24:5026)
    at Object.B [as executePackageScript] (/usr/local/lib/node_modules/yarn/bin/yarn.js:24:5159)
    at async c.execute (/usr/local/lib/node_modules/yarn/bin/yarn.js:58:43949)
    at async c.validateAndExecute (/usr/local/lib/node_modules/yarn/bin/yarn.js:24:40434)
    at async c.run (/usr/local/lib/node_modules/yarn/bin/yarn.js:36:533800)
    at async s.execute (/usr/local/lib/node_modules/yarn/bin/yarn.js:58:17806)

yarn version: 2.0.0-rc.27

2reactions
larixercommented, Apr 2, 2020

@FredrikAugust Another workaround is "lint": "eslint 'src/**/*.{tsx,ts}'"

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Package.json syntax error? - Stack Overflow
The JSON appears to be valid (I ran it through an online parser). I ran the same package.json under windows and got the...
Read more >
package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >
Error Codes | Yarn - Package Manager
A list of Yarn's error codes with detailed explanations. ... Please relinquish one character and use the YNX prefix (ex YNX001 ) instead...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug :1523 - "[IDEA] Offload work by distributing trivial ebuild maintenance to users, ... has package.use.masked doc on amd64 due to out of...
Read more >
CommonJS modules | Node.js v19.3.0 Documentation
Below, bar.js makes use of the square module, which exports a Square class: ... Parse DIR/NAME/package.json, and look for "exports" field. 4.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found