Unexpected token error in Task Runner - javascript

After updating VS 2015 to Update 2 gulp is failing executed by Task Runner Explorer, but it works fine from console.
The error is known, but I don't know how it is related to VS 2015. It does work well in VS 2013. Does VS using a different javascript interpreter than nodeJs or VS 2013 do?
It is a Windows 7, Node.js 5.10.1.
Error:
Failed to run "C:\..\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
C:\..\node_modules\gulp-inject\src\inject\index.js:127
startTag,
^
SyntaxError: Unexpected token ,
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\..\node_modules\gulp-inject\index.js:4:28)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Failed to run "C:\..\package.json"...
Failed to run "C:\..\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
C:\..\node_modules\gulp-inject\src\inject\index.js:127
startTag,
^
SyntaxError: Unexpected token ,
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\..\node_modules\gulp-inject\index.js:4:28)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Update:
I have another machine with Windows 10, Node.js 5.10.1 and with Visual Studio 2015 Update 2 where the same stuff works fine

I had this problem recently too - I found updating VS to use my global node install fixed it for me:
https://github.com/VirtoCommerce/vc-community/issues/247#issuecomment-174454440

I had the same problem, but it turned out to be an issue of having an older version of NodeJS. I found this issue on github that helps:
https://github.com/klei/gulp-inject/issues/172
Once updated my NodeJS version to the latest, Gulp was working fine.

Related

Struggling with running Storybook

Hi I'm a beginner learning React & I'm trying out Storybook and I am having the following error when I try to run Storybook. **I tried to update by using npm update, I thought there was conflict with my dependencies **
ERROR in ./.storybook/generated-refs.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: You gave us a visitor for the node type StaticBlock but it's not a valid type
at verify (C:\Users\msngw\OneDrive\Desktop\SBook\myapp\node_modules\#babel\traverse\lib\visitors.js:112:13)
at explode (C:\Users\msngw\OneDrive\Desktop\SBook\myapp\node_modules\#babel\traverse\lib\visitors.js:34:3)
at Object.merge (C:\Users\msngw\OneDrive\Desktop\SBook\myapp\node_modules\#babel\traverse\lib\visitors.js:147:5)
at Object.<anonymous> (C:\Users\msngw\OneDrive\Desktop\SBook\myapp\node_modules\#babel\helper-replace-supers\lib\index.js:60:44)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\msngw\OneDrive\Desktop\SBook\myapp\node_modules\#babel\helper-create-class-features-plugin\lib\fields.js:13:52)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
# multi ./node_modules/#storybook/core/dist/server/common/polyfills.js ./node_modules/#storybook/core/dist/client/manager/index.js ./node_modules/#storybook/addon-links/dist/register.js ./node_modules/#storybook/addon-actions/dist/register.js ./node_modules/#storybook/addon-docs/dist/register.js ./node_modules/#storybook/addon-controls/dist/register.js ./node_modules/#storybook/addon-backgrounds/dist/register.js ./node_modules/#storybook/addon-viewport/dist/register.js ./node_modules/#storybook/addon-toolbars/dist/register.js ./.storybook/generated-refs.js main[9]
This bug has been already raised in the Storybook repo. As mentioned there, removing yarn.lock and node_modules, then re-installing using yarn, fixed all issues.

Error: Cannot find module 'update-notifier'. I cannot install any NPM

There is a similar question on StackOverFlow but it was unhelpful and it wasn't answered. I have been working on a project and I currently am receiving this error.
Error: Cannot find module 'update-notifier'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:29:19
at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:92:3)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
If I type any command that includes npm it returns the same error, I can't install anything.
I have tried to uninstall/re-install NodeJS with homebrew but nothing changed from trying that.

Node JS Ubunto Production require error

I have deployed my Node js Application to digitalocean Ubuntu servers. Everything runs fine on localhost. For some reason when I start my node app using "node app.js" on ubuntu digital ocean, I am thrown "Cannot find module '../../Models". The "models" directory includes a few files that i have created including an index.js. My app is correctly configured and installed and I have been working on solving this issue for 2 days. Is ubuntu case sensitive for locating directories? I can't seem to figure out why my modules cannot be located. Thanks.
deploy#yw://home/deploy/ywapp$ node app
module.js:340
throw err;
^
Error: Cannot find module '../../Models'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/deploy/ywapp-1455754628602/routes/access_token/token.js:4:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/deploy/ywapp-1455754628602/routes/access_token/index.js:2:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/deploy/ywapp-1455754628602/routes/auth/user.js:13:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)

Logging caught errors exactly the same as uncaught errors in Node.js

Let's say I have the following file error.js:
// this is invalid code
var a: 0;
And then in my main.js I require that file:
require("./error.js");
I get a nice, simple, and easy to understand error message from Node.js:
$ node main.js
/home/jfischer/error.js:2
var a: 0;
^
SyntaxError: Unexpected token :
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/jfischer/main.js:1:63)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
Now let's try to wrap this in a try/catch block, and print the error by changing main.js to:
try {
require("./error.js");
}
catch(err) {
console.log(err.stack);
}
But now we get:
$ node main.js
SyntaxError: Unexpected token :
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/home/jfischer/main.js:3:5)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
How can I get the much more human friendly part pointing out the exact file and line of code node broke at in a string?:
var a: 0;
^
The Node.js documentation does not appear to expose anything beyond the stack property; message and name are less helpful.
I'm interested for logging errors to files or other custom error logging solutions. Any help would be appreciated.
The information is missing when you run the code with Node.js 4, but in Node.js 6 and newer, the helpful information is provided even if the error is caught. Node.js 4 is no longer supported and I imagine by this point you're not using it anymore. But if you or anyone is: Use Node.js 6 or newer and you'll get the information you want.
$ nvm use 4
Now using node v4.9.1 (npm v2.15.11)
$ node -v
v4.9.1
$ node main.js
SyntaxError: Unexpected token :
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/Users/trott/temp/main.js:2:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
$ nvm use 6
Now using node v6.15.1 (npm v3.10.10)
$ node -v
v6.15.1
$ node main.js
/Users/trott/temp/error.js:2
var a: 0;
^
SyntaxError: Unexpected token :
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/trott/temp/main.js:2:1)
$
Latest node v11 shows every detail even from the imported module.

Encounter TypeError with casperjs

when I execute casperjs, it throws an TypeError:
#casperjs test.js
child_process.js:936
var r = this._handle.spawn(options);
^
TypeError: Bad argument
at ChildProcess.spawn (child_process.js:936:24)
at exports.spawn (child_process.js:736:9)
at Object.<anonymous> (/usr/local/lib/node_modules/phantomjs/bin/phantomjs:22:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
and without test.js it throws same error:
# casperjs
child_process.js:936
var r = this._handle.spawn(options);
^
TypeError: Bad argument
at ChildProcess.spawn (child_process.js:936:24)
at exports.spawn (child_process.js:736:9)
at Object.<anonymous> (/usr/local/lib/node_modules/phantomjs/bin/phantomjs:22:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
casperjs was installed with following command refer to http://docs.casperjs.org/en/latest/installation.html#installing-from-npm:
$ npm install -g casperjs
thanks a lot in advance if any one can help on it.
Found the issue came from phantomjs:
#phantomjs hello.js
child_process.js:936
var r = this._handle.spawn(options);
^
TypeError: Bad argument
at ChildProcess.spawn (child_process.js:936:24)
at exports.spawn (child_process.js:736:9)
at Object.<anonymous> (/usr/local/lib/node_modules/phantomjs/bin/phantomjs:22:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
after reinstall phantomjs the issue was gone:
npm install -g phantomjs
A CDN site:
PHANTOMJS_CDNURL=http://cnpmjs.org/downloads npm install -g phantomjs
Both phantomjs and casperjs goes right:
# phantomjs -v
1.9.8
# phantomjs hello.js
Hello, world!
#casperjs test.js
百度一下,你就知道
The root cause seems to be that a broken phantomjs was installed before, when executed phantomjs it source the broken version.
Thanks the guys upping the questions.
Wish this expierence will help others.
Best Regards
-Radon

Categories