Node - Unexpected or invalid token in line 1, after reinstalling Windows - javascript

I have a JavaScript file that I could run just fine yesterday. I reinstalled Windows last night, reinstalled Node this morning, and I'm trying to run the same JavaScript file now, but its giving me an error.
$ node index.js
C:\Users\<user-name>\Google Drive\Projects\<blah>-coding\index.js:1
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
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 Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3

code is Unicode and not working, just save as UTF-8, working great!

Related

Problem to execute gulp server at legacy app

Yo guys!
I get early a job on a legacy app, using gulpjs
After having installed all dependencies, when I try execute the application with "gulp server", get the following error at console:
D:\scripts\node_modules\gulp-sass\index.js:186
).toString();
^
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> (D:\Playkids\playkids-simple-pages\scripts\tasks\development.js:4:12)

backend suddenly stopped working and threw this error "Cannot find module '../../cast/boolean'"

A day before my project was working fine the next day this showed up when I ran nodemon command:
module.js:471
throw err;
^
Error: Cannot find module '../../cast/boolean'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (h:\Backend\notecrates_backend\node_modules\mongoose\lib\schema\operators\exists.js:3:21)
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)
[nodemon] app crashed - waiting for file changes before starting...
I run my project on visual studio and I closed visual studio directly
while my project was running may be this caused the problem??

JavaScript settings. brain js

I have downloading VS Code, downloading brain.js using npm, found example but I get this error in console all the time.
Debugger listening on ws://127.0.0.1:31661/83ca1086-743d-46cf-96bc-4bb352980d2b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
/Users/user/Downloads/using-machine-learning-to-determine-light-or-dark/js/index.js:1
(function (exports, require, module, __filename, __dirname) { const input =
document.querySelector("input")
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
Waiting for the debugger to disconnect...
ReferenceError: document is not defined
index.js:1
at Object.<anonymous> (/Users/user/Downloads/using-machine-learning-to-determine-light-or-dark/js/index.js:1:77)
at Module._compile (internal/modules/cjs/loader.js:675:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
How can I solve it?
document.querySelector("input") leads to document is not defined. The issue: You are running browser code in your console.

can't launch first example for Cucumber+javascript

I tried to launch first example from official documentation here
https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md
I used Windows 7x64 bit , node.js 6.11
I tried the following commands and got the same result
*
node_modules/cucumber/bin/cucumber.js autotests/cucumber-test/features/documentation.feature
node_modules\cucumber\bin\cucumber.js autotests\cucumber-test\features\documentation.feature
cucumber autotests\cucumber-test\features\documentation.feature
cucumber-js autotests\cucumber-test\features\documentation.feature
*
and I got the following error
cucumber.js:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
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 Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at getDefinitions (<path>\node_modules\cucumber\lib\cucumber\cli\profiles_loader.js:8:23)
I also tried to downgrade to cucumber 1.3.3 but it doesn't help
Please try below command:
node_modules\cucumber\bin\cucumber.js.cmd autotests\cucumber-test\features\documentation.feature
I found solution
1) npm init -> and define package.json
2) npm install cucumber#latest
3) node_modules\.bin\cucumber.js.cmd <path>\myfeature.feature

Cannot run Javascript code on Atom editor

Atom is not able to run javascript code for some reason, I have tried both packages such as atom runner and atom script with no success.
I have Node JS installed on my computer and javascript package installed on Atom, I have no idea why it does not work.
Here is the code which is returned after trying to run a javascript prompt.
C:\Users\artisan\Desktop\hi.js:1
(function (exports, require, module, __filename, __dirname) { var hi = prompt("wt");
^
ReferenceError: prompt is not defined
at Object.<anonymous> (C:\Users\artisan\Desktop\hi.js:1:72)
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.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
prompt() is a function which is implemented by Web Browsers.
In serversided JS you can't use this function.

Categories

Resources