I am developing a serverless NodeJS app and need to test it in offline mode. I have an npm script in a package.json file that looks like this:
"scripts": {
"serve": "cross-env AUTHORIZER='{\\\"claims\\\":{\\\"permissions\\\":\\\"[view:accounts manage:accounts]\\\",\\\"sub\\\":\\\"auth0|5cfe0adce3c4c50ea072ea9f\\\"}}' AWS_PROFILE=elit_nonprd serverless offline start -s dev --noAuth",
...
Note that there two permissions that need to be separated by a space. Running npm run serve on Windows gives the following error:
> @mypackage@1.0.0 serve C:\path
> cross-env AUTHORIZER='{\"claims\":{\"permissions\":\"[view:accounts manage:accounts]\",\"sub\":\"auth0|5cfe0adce3c4c50ea072ea9f\"}}' AWS_PROFILE=elit_nonprd serverless offline start -s dev --noAuth
The filename, directory name, or volume label syntax is incorrect.
events.js:288
throw er; // Unhandled 'error' event
^
Error: spawn manage:accounts]","sub":"auth0|5cfe0adce3c4c50ea072ea9f"}} ENOENT
at notFoundError (C:\path\node_modules\cross-spawn\lib\enoent.js:6:26)
at verifyENOENT (C:\path\node_modules\cross-spawn\lib\enoent.js:40:16)
at ChildProcess.cp.emit (C:\path\node_modules\cross-spawn\lib\enoent.js:27:25)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess.cp.emit (C:\path\node_modules\cross-spawn\lib\enoent.js:30:37)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12) {
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn manage:accounts]","sub":"auth0|5cfe0adce3c4c50ea072ea9f"}}',
path: 'manage:accounts]","sub":"auth0|5cfe0adce3c4c50ea072ea9f"}}',
spawnargs: [
'AWS_PROFILE=elit_nonprd',
'serverless',
'offline',
'start',
'-s',
'dev',
'--noAuth'
]
}
This also happens if I replace cross-env with cross-env-shell, although the stack-trace is not shown.
Is there a common cross-platform way to set environment variables when the values contain spaces?
Update: the outcome I am hoping for is to set AUTHORIZER to the following value (thanks to @RobC for requesting clarification):
{
"claims":
{
"permissions": "[view:accounts manage:accounts]",
"sub": "auth0|5cfe0adce3c4c50ea072ea9f"
}
}