Visual Studio 2017, Task Runner Explorer not loading module - node.js

I am trying to build my project from Task Runner Explorer.
Project is running fine from cmd, using au run.
The error generates is below:
Failed to run "D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\Gulpfile.ts"...
cmd.exe /c gulp --tasks-simple
D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\gulpfile.js:1
(function (exports, require, module, __filename, __dirname) { define(["require", "exports", "gulp", "gulp-shell"], function (require, exports, gulp, gulp_shell_1) {
^
ReferenceError: define is not defined
at Object.<anonymous> (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\gulpfile.js:1:63)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at execute (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\node_modules\gulp\node_modules\gulp-cli\lib\versioned\^4.0.0-alpha.2\index.js:37:18)
at Liftoff.handleArguments (D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\node_modules\gulp\node_modules\gulp-cli\index.js:173:63)
I have below code in Gulpfile.ts
import * as gulp from 'gulp';
import shell from 'gulp-shell';
gulp.task('build-dev', shell.task(['au build --env dev']));
Note: I have used both SystemJS and RequireJS module loader.
I am assuming, the issue is simple that i need to tell somehow to use SystemJS loader either in tsconfig.json or package.json or ???
Any help is appreciated. May be I should provide more detail, but could not justify what. Please comment, if any context can help in resolving above issue.
Thanks.

Just in case you're still experiencing this problem;
It appears that the globally installed gulp in C:\Users\{user}\AppData\Roaming\npm\node_modules is an outdated version and that this is where the task runner runs from regardless of what you have defined in your package.json.
In the node.js command prompt, you can uninstall gulp globally using:
npm uninstall gulp -g
As I had gulp declared in my project this actually fixed the problem.
But really what you need is the gulp 4 installed globally;
npm install gulp#next -g
Happy coding!

In Visual Studio Tools->Options->Projects and Solutions->Web Package Management.
Moving $(Path) to first index has resoloved the above issue, may be it was because of node or something else version issue installed independently and in VS.
But still getting another issue at later stage of running task.
The new error is below obviously, it is something else, Can anybody guide a good read overcome these issue:
Failed to run "D:\Irshad\Practice\Aurelia\Demo\AureliaDemo2\Gulpfile.ts"...
cmd.exe /c gulp --tasks-simple
C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:147
console.log(Object.keys(localGulp.tasks)
^
TypeError: Cannot convert undefined or null to object
at logTasksSimple (C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:147:22)
at C:\Users\irshad.ali\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:124:14
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
I have written this as answer but not market as answer, waiting for a great answer. :)

Related

Can't run Jest tests from editor in WebStorm

I'm looking at a file in WebStorm that contains Jest tests. I can run Jest via a run configuration and it works fine.
However, I can't right-click on a test in the editor and run it, nor do I get any gutter icons that would let me do so. I can right-click on a describe or it block and I have the option to run or debug, but it's trying to run/debug the file, not run the test:
(function (exports, require, module, __filename, __dirname) { import React from "react";
^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
Process finished with exit code 1
This is a new installation on a new M1 MacBook Pro, but it's got my settings synced with my other machines, so I don't see any reason why this wouldn't work like all my other WebStorm installations. (And it's not just this file, it's any test file anywhere.)
The problem solved itself when I removed babel-jest from our dependencies and added jest, which hadn't previously been there even though the tests would run, including using the "Run tests" run config.
As #lena suggested, the problem appeared to be not having Jest in the package file.

Firebase cloud functions suddenly returns #grpc module error

I'm finding Firebase Cloud Functions to be quite unreliable.
What happened:
I had one function working as expected (function A), already deployed and okay.
As I was building another one (function B), unrelated to A, cloud functions logs started reporting the following error:
Error: Cannot find module '#grpc/grpc-js'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/node_modules/google-gax/build/src/grpc.js:37:14)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
Maybe I messed something up. So I removed function B and deployed again. The errors still kept appearing, and function A was no longer working.
How I tried to solve:
Removed the node_modules folder and ran npm install again.
Installed, again, the grpc module with npm install --save grpc.
Nothing has solved the problem.
Any ideas on what am I doing wrong? And also on how to avoid this from happening again?
Thanks in advance for any help!
I could not figure the reason for this behavior.
However, by following Paul Kinlan's suggestion, the error went away (no changes in the functions whatsoever).
npm install
npm rebuild --build-from-source google-cloud
I also performed a npm update to make sure I had all the latest packages, following Doug's comment in my question.
If anyone figures out the cause of this error, please drop a note so we can avoid it in the future.
Try deleting the cloud function from the console and then upload it again.

A module does not compile in a newer node.js version, any workarounds?

my open-source project depends on a lemmatization module —
https://github.com/grachev/node-lemmer
— which needs to be compiled before it can run.
After updating to a newer version of node.js I can't run this module, because it needs to be re-compiled. Usually this was done when I simply did npm install node-lemmer however it is now not available in npm and I don't know how to compile it under that new node version and why I have to do it at all...
I tried running npm rebuild but it does not recompile – too many errors. The issues folder of that project on GitHub has the issue up already but there's no fix for it...
What could I do about it? Why do I need to recompile this module when I install a new version of node? Is there a workaround? Could I "trick" node or that module so it doesn't need to recompile? Or maybe it's possible to compile it manually?
...
Some mode details:
I used to run my project on node 0.8.3 vesion and then switched to the new 8.8.0 version. Now when I try to run my project under the new node version it doesn't start giving the following error:
module.js:641
return process.dlopen(module, path._makeLong(filename));
^
Error: Module did not self-register.
at Object.Module._extensions..node (module.js:641:18)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Module.require (module.js:556:17)
at require (internal/module.js:11:18)
at Object.<anonymous>
(/path-to-my-project/node_modules/node-lemmer/lib/node-lemmer.js:1:82)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
which is an error I've seen before because my module could not be compiled.
my project is https://github.com/noduslabs/infranodus in case it helps to see the source code.

Creating a dev environment from existing website with nodejs

So I've used Node.js in the past before, but I've never created a development environment from a pre-existing website. And now I have to. Plus, the previous developer worked in another state and used an iMac and developed in Coda. We were able to get all the files to my current workspace but I am trying to create the project in Visual Studio with Node Tools and am running into an issue. I fairly certain that its some kind of routing/config/setup issue but have not been able to suss it out and I've been rooting through package.json and config files for days.
All files are in the same relative directory from the root yet, and I've updated all packages and adjusted the code accordingly (I believe for the updated packages). However, when I try to start the site up, I run into this issue.
Debugger listening on [::]:5858
T:\IT\Website\ComfortCo(Dev)\ComfortCo(Dev)\views\index.jade:1
(function (exports, require, module, __filename, __dirname) { extends global_layout
^^^^^^^
SyntaxError: Unexpected token extends
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
Press any key to continue...
The site uses jade with express and this is a pretty basic function of jade layouts. So I do not know why there is a Syntax Error.
Any ideas?
Update
So I was told that I did not have the most up-to-date versions of Node except I installed the most current version of Node when I installed Node Tools for VS and the pathing is correct.
However, when I ran npm list and npm list -g they came back with nothing even though my projects npm repository shows a whole list of packages installed and up-to-date. So I can only conclude that their is some pathing issue here. However, I have never configured Node paths. I've always just left them default. Any guidance here?
The extends keyword is supported since Node version 4.x - see:
http://node.green/#ES2015-functions-class-extends
It seems that you may be running an older version of Node but of course it's hard to tell because you provided no information about your runtime environment whatsoever.

Microsoft Azure - Gulp 3.8.10 does not work on fresh Web App instance

I am using a fresh instance of a Web App with Node 12.3 and NPM 2.9.1. Gulp PATH appears to be set to D:\Program Files (x86)\gulp\3.8.10. I believe Gulp 3.8.10 has a bug that should be fixed with an update to 3.8.11. I am unable to use gulp until this is worked out... Unless there is another way to handle this? Any help from the Azure team would be appreciated. Deploying with Gulp has been a thorn in my side on this platform. I am trying to use vNext deployment with Angular and WebApi... My gulp CI builds can't move forward because of this. Thanks for anyone able to help!
I think this issue is noted here https://github.com/gulpjs/gulp/issues/893
Kudu Remote Execution Console
Type 'exit' then hit 'enter' to get a new CMD process.
Type 'cls' to clear the console
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
D:\home>gulp -v
module.js:338
throw err;
^
Error: Cannot find module 'D:\Program Files (x86)\gulp\3.8.10\node_modules\gulp\node_modules\v8flags\3.28.73.flags.json'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (D:\Program Files (x86)\gulp\3.8.10\node_modules\gulp\bin\gulp.js:25:22)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
The short version:
You can install your own version of gulp where ever you have access, say D:\home\npm_tools\ for example, then override the default gulp path by setting an AppSetting GULP_PATH = D:\home\npm_tools\
The long version:
1) Go the DebugConsole above
2) npm config set prefix "D:\home\npm_tools" (or where ever you want it to be)
3) npm install -g gulp (or you can really zip up the folder from your machine and drop it somewhere if your machine is also running windows)
4) Go to portal or where you manage you app settings and set GULP_PATH = D:\home\npm_tools\
5) Refresh the DebugConsole
6) gulp -v, you should get 3.9.0 if you've just install the latest at the time of writing this comment
I realize this is a bit hacky and manual, but it should get you unblocked until we update that gulp version
I just tested gulp -v on a fresh Azure Web App. Gulp is present. Since you're experiencing a difficulty, you could try installing it.
Go to your-domain.scm.azurewebsites.net
Choose Debug console > CMD
Run npm install gulp
Test with gulp -v

Resources