[Bug] Syntax error in parsing package.json run scripts with env variable using ' prefixed
See original GitHub issuevia @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:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 inyarn version: 2.0.0-rc.27
@FredrikAugust Another workaround is
"lint": "eslint 'src/**/*.{tsx,ts}'"