Skip to content

Conversation

@markgoho
Copy link
Contributor

Leaving the explicit paths in, I get this error:

$ npm run build > functions@ build C:\Users\Nella\Documents\GitHub\dutchess-church\functions > tslint -p tslint.json && ./node_modules/.bin/tsc '.' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! functions@ build: `tslint -p tslint.json && ./node_modules/.bin/tsc` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the functions@ build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Nella\AppData\Roaming\npm-cache\_logs\2017-12-10T01_49_04_598Z-debug.log 

Here is the debug log:

0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 1 verbose cli 'run', 1 verbose cli 'build' ] 2 info using npm@5.5.1 3 info using node@v8.9.3 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ] 5 info lifecycle functions@~prebuild: functions@ 6 info lifecycle functions@~build: functions@ 7 verbose lifecycle functions@~build: unsafe-perm in lifecycle true 8 verbose lifecycle functions@~build: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\Nella\Documents\GitHub\dutchess-church\functions\node_modules\.bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Nella\bin;C:\Program Files\ImageMagick-7.0.7-Q16;C:\Python27;C:\Python27\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\PuTTY;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files (x86)\Yarn\bin;C:\Program Files\nodejs;C:\Ruby23\bin;C:\Users\Nella\AppData\Local\Microsoft\WindowsApps;C:\Users\Nella\AppData\Local\GitHubDesktop\bin;C:\Program Files\Microsoft VS Code Insiders\bin;C:\Users\Nella\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\Nella\AppData\Local\Yarn\bin;C:\Users\Nella\AppData\Roaming\npm 9 verbose lifecycle functions@~build: CWD: C:\Users\Nella\Documents\GitHub\dutchess-church\functions 10 silly lifecycle functions@~build: Args: [ '/d /s /c', 10 silly lifecycle 'tslint -p tslint.json && ./node_modules/.bin/tsc' ] 11 silly lifecycle functions@~build: Returned: code: 1 signal: null 12 info lifecycle functions@~build: Failed to exec build script 13 verbose stack Error: functions@ build: `tslint -p tslint.json && ./node_modules/.bin/tsc` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:280:16) 13 verbose stack at emitTwo (events.js:126:13) 13 verbose stack at EventEmitter.emit (events.js:214:7) 13 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14) 13 verbose stack at emitTwo (events.js:126:13) 13 verbose stack at ChildProcess.emit (events.js:214:7) 13 verbose stack at maybeClose (internal/child_process.js:925:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) 14 verbose pkgid functions@ 15 verbose cwd C:\Users\Nella\Documents\GitHub\dutchess-church\functions 16 verbose Windows_NT 10.0.17025 17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" 18 verbose node v8.9.3 19 verbose npm v5.5.1 20 error code ELIFECYCLE 21 error errno 1 22 error functions@ build: `tslint -p tslint.json && ./node_modules/.bin/tsc` 22 error Exit status 1 23 error Failed at the functions@ build script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ] 

Removing the explicit paths from the script makes it run just fine. I thought when things were run as an npm script, you didn't need to give explicit paths. I'm in Windows, which probably matters here.

@nicolasgarnier
Copy link
Contributor

@inlined @mbleigh this is autogenerated from firebase init when we choose TypeScript as the language for the new project. Maybe we should change this in firebase-tools directly?

@inlined
Copy link
Member

inlined commented Dec 11, 2017

I'm trying to get ahold of a windows VM so I can dive into this better. The explicit path is very intentional; it means each project uses the (package) locally installed version of tsc so the developer can have some semblance of control over their tools.

I'd like to find a way to have:

  1. A dependency on the locally installed version of tsc
  2. A command that works on Windows
  3. A command that isn't determined by the OS that was used to initialize the project (e.g. same command for Windows and *nix)
@markgoho
Copy link
Contributor Author

markgoho commented Dec 23, 2017

@inlined Update: running the command with yarn instead of npm works!

So, running yarn build builds the .js files just fine. Running yarn serve (which in the package.json file uses npm run build) fails.

Changing the npm run commands to yarn results in:

=== Serving from 'C:\Users\Nella\Documents\GitHub\KingstonChurchNg4'... ! functions: Cannot start emulator. Error: Cannot find module 'C:\Users\Mark\AppData\Local\Yarn\config\global\node_modules\grpc\src\node\extension_binary\node-v57-win32-x64-unknown\grpc_node.node'
@inlined
Copy link
Member

inlined commented Dec 26, 2017

Sorry it took so long to get ahold of a Windows machine. This bug is fascinating. There's a few things at play here:

  1. Windows does allow dot-relative paths in commands. This does the same thing as Unix and is highly recommended for security and predictability (If I had a nickel for every machine hacked when a program loads a local dll from the search path...)
  2. Windows obviously doesn't use '/' as a path separator, though many scripting tools paper over this, like 'node run'
  3. Unfortunately, 'node run' doesn't understand '&&' implies there are two commands and only fixes up the first command we run.

We'll do a proper fix in an upcoming release of firebase-tools but in the meantime, you can fix it for your own project. We'll need to move the "&&" up a level to something that's not using slashes. So....

  1. Change your package.json build command to be "./node_modules/.bin/tsc".
  2. Add a lint command with "./node_modules/.bin/tslint -p tslint.json"
  3. Change your firebase.json predeploy command to be "npm --prefix functions run lint && npm --prefix functions run build"

So to recap, after this fix your package.json should have the following snippet:

{ "scripts": { "lint": "./node_modules/.bin/tslint -p tslint.json", "build": "./node_modules/.bin/tsc" } // other stuff }

and your firebase.json should have the following:

{ "functions": { "predeploy": "npm --prefix functions run lint && npm --prefix functions run build" } }

This should give you a project setup that is predictable, safe, and cross-platform compatible.

@inlined inlined closed this Dec 26, 2017
@markgoho markgoho deleted the patch-2 branch December 30, 2017 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants