Why do I keep getting this Node SyntaxError after a while? - node.js

Can anyone help me with this SyntaxError?
I keep getting it on various paths not only mongoose, sometimes is bluebird sometimes another module.
Tried and deleted the node_modules folder and reinstall the npm modules which fixes the issue but after a couple of runs of the script, it appears again.
I honestly can't explain why it works after reinstalling the node_modules and after a few runs, it doesn't anymore.
Node: v9.8.0
NPM: 5.7.1
node_modules/mongoose/lib/options.js:1
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
at new Script (vm.js:51:7)
at createScript (vm.js:136:10)
at Object.runInThisContext (vm.js:197:10)
at Module._compile (module.js:613:28)
at Object.Module._extensions..js (module.js:660:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)

You are having that SyntaxError because you have some broken files in your npm installations probably due to a fluctuation in your internet or any other reason. And you still got that same error after deleting the node_modules folder and re-install the npm modules again because of the same thing I said.
So your problem got fixed that last time because after you re-installed all the required dependencies ere fully installed in your node_modules.

Related

How to uninstall a node module completely?

UPDATE
I don't have a problem with my ionic module, but with my node install(s).
It seems I have 4 node installs:
running npm start on a createreactapp installed with v15.6.0, I get:
so somehow it is using node 4.5.0.
What’s going on?
Original post:
I have a module, that is malfunctioning. Uninstalling and reinstalling it ultimately results in the same error. And I can see, that uninstalling it doesn't get rid of all the files.
Specifics:
The module in question is Ionic
The error I'm getting ever since I tried to update it is:
/usr/local/lib/node_modules/#ionic/cli/node_modules/semver/internal/re.js:1
(function (exports, require, module, __filename, __dirname) { const { MAX_SAFE_COMPONENT_LENGTH } = require('./constants')
^
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> (/usr/local/lib/node_modules/#ionic/cli/node_modules/semver/index.js:2:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
it is shown whenever I run an ionic command, even ionic --help
(btw. this line, that is shown from rs.js is the first line of the file)
I've tried uninstalling it with npm uninstall -g #ionic/cli
and npm uninstall -g ionic
(I also once accidentally typed npm uninstall - ionic. and it did something...)
And reinstalling it with npm install -g #ionic/cli
Tried this several times.
I've also updated node to 15.6.0.
--
I have to admit I'm generally a bit confused about node modules and where they live.
Because for Ionic there are files (I'm using MacOs 11.2.3) in /usr/local/lib/node_modules/#ionic/
But also in [user folder]/node_modules/#ionic
And there's a .ionic in the user folder.
Perhaps there is something I don't understand
How do I go about issues such as this?

Trying to create Vue app, but getting "SyntaxError: Unexpected identifier" when running command in terminal

I have been working in AngularJS for a while now and I decided to try out Vue. I installed Vue using npm install -g #vue/cli in my terminal using Node version 6.4.0. After the installation was complete I tried creating a new app using vue create <name of app>. It's during this seemingly simple step that I am getting hung up with this error:
/Users/jonalden/.nvm/versions/node/v6.4.0/lib/node_modules/#vue/cli/node_modules/open/index.js:16
const wslToWindowsPath = async path => {
^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:528:28)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/jonalden/.nvm/versions/node/v6.4.0/lib/node_modules/#vue/cli/node_modules/#vue/cli-shared-utils/lib/openBrowser.js:9:14)
at Module._compile (module.js:556:32)
I have tried downgrading Node to a previous version and reinstalling Vue with Yarn but both were unsuccessful. One thing throwing me off here is the line wslToWindowsPath, which is especially weird since I am on a Mac.
I had the same problem. I've done this :
sudo rm -rf ~/.nvm

gulp syntaxe error after installation

Ok so I have a problem installing gulp in my project. I followed the steps on the installation guide but I get a SyntaxError when trying to run their default example.
I just installed gulp with : npm install --global gulp-cli and npm install --save-dev gulp
I created a file named gulpfile.js at the parent of my project and then added the following code to the file :
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
Then I runed gulp in powershell located at the parent of my project expecting to execute nothing because there is no code in my task but I received the following error :
PS D:\Users\UserName\project> gulp
D:\Users\UserName\project\gulpfile.js:1
(function (exports, require, module, __filename, __dirname) { ��v
^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at execute (C:\Users\UserName\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^3.7.0\index.js:28:18)
PS D:\Users\UserName\project>
My gulp version after installation are :
[18:56:36] CLI version 2.0.1
[18:56:36] Local version 3.9.1
and my npm version is :
5.6.0
Note that I also tried with actuall task and got the same result
I would like to know what I did wrong or what I need to do to resolve the problem.
As Felix Kling said in the comments, there was strange characters in the beginning of my gulpfile.
Indeed, when I copied and pasted the code, it added the hindden caracter for Control-V...

NodeJS stopped working after changing version

I was working on Node version 9.1.0 but the client asked me to use NVM so that the version can be switched at will. I tried but it was not working. So I uninstalled NodeJS from my windows machine and did a fresh install of NodeJS version 8.9.4
After npm install when I tried to execute the code I got this error:
SyntaxError: Unexpected number
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\inetpub\wwwroot\NodeJS_APIs\api\node_modules\lodash\isFunction.js:1:80)
The line that trew the error is in vm.js:
function createScript(code, options) {
return new Script(code, options);//This is the line
}
I don't understand what went wrong. Can someone please explain what am I doing wrong?
From your error stacktrace it seems the error is related to your loadash library, Can you please try uninstalling it using,
npm uninstall lodash
And then reinstall a compatible lodash version like this,
npm install lodash#4.17.5
Once done, try running your script again.
Hope this helps!
You might get some hints from here, although I’m not sure: https://github.com/rollup/rollup/issues/2054

NodeJS Module "userid" Error: Module version mismatch. Expected 46, got 47

I get the following error when trying to start my server.js which requires the module "userid".
module.js:460
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 46, got 47.
at Error (native)
at Object.Module._extensions..node (module.js:460:18)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/root/backend/node_modules/userid/lib/userid.js:2:15)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
How can I solve this issue?
Not sure of the exact meaning of this error but my fix for this is to delete the node_modules directory and reinstall the required modules with npm install.
The above is a solution for this error showing up in a node project which uses locally installed modules. If there are some global modules that are throwing this error then you might have to reinstall those.
I would try upgrading the module version that causes the issue on package.json.
Another reason of this problem is that you have several different node versions installed at your system and you manage them with nvm. If you run node index.js and if you run sudo node index.js it may results in running different node version.
So if you installed your application modules with npm install and then run application with sudo node index.js you will have Module version mismatch error. In such case make sure with nvm that sudo node... run the same version of node as your application expects.
Also, while fixing initial problem you may have problem with nvm described here Can't use NVM from root (or sudo). One of possible solutions to this issue described in Yoo Matsuo's comment.

Resources