Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

functions deploy fails on Windows #34

Closed
yi-jiayu opened this issue Feb 11, 2017 · 0 comments
Closed

functions deploy fails on Windows #34

yi-jiayu opened this issue Feb 11, 2017 · 0 comments
Labels

Comments

@yi-jiayu
Copy link

Description

This line

const exportedKeys = execSync(`node -e 'console.log(Object.keys(require("${opts.localPath}") || {}))'`).toString().trim();

at https://github.com/GoogleCloudPlatform/cloud-functions-emulator/blob/master/src/cli/controller.js#L100 causes functions deploy to fail on Windows.

Steps to reproduce

Follow instructions on https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki until step 5

  1. Deploy your function:
functions deploy helloWorld --trigger-http

This will fail on Windows:

PS C:\Users\jiayu\Documents\some-project> functions deploy helloWorld
[eval]:1
'console.log(Object.keys(require(C:\Users\jiayu\Documents\some-project)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
    at Object.exports.runInThisContext (vm.js:76:16)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:570:32)
    at bootstrap_node.js:357:29
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
'{}))'' is not recognized as an internal or external command,
operable program or batch file.
ERROR: Command failed: node -e 'console.log(Object.keys(require("C:\Users\jiayu\Documents\some-project") || {}))'
[eval]:1
'console.log(Object.keys(require(C:\Users\jiayu\Documents\some-project)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
    at Object.exports.runInThisContext (vm.js:76:16)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:570:32)
    at bootstrap_node.js:357:29
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
'{}))'' is not recognized as an internal or external command,
operable program or batch file.

PS C:\Users\jiayu\Documents\some-project>

There appear to be two underlying issues causing this:

  1. cmd.exe handling of single quotes - cmd.exe doesn't recognise the argument to node -e wrapped in single quotes and tries to execute the portion after the space
  2. Node.js path module behaviour on Windows - path.resolve uses backslash path separators on Windows which causes problems when the path is used as a command line argument.

Swapping the single quotes and double quotes and replacing backslashes in the resolved path with forward slashes fixed the issue for me:

const exportedKeys = execSync(`node -e "console.log(Object.keys(require('${opts.localPath.replace(/\\/g, '/')}') || {}))"`).toString().trim();

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants