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...
Related
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?
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
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.
If you run gulp, you will get the following error message.
Is module required for gulpfile not installed? ..
$ gulp
[22:17:15] Failed to load external module ts-node/register
[22:17:15] Failed to load external module typescript-node/register
[22:17:15] Failed to load external module typescript-register
[22:17:15] Failed to load external module typescript-require
C:\project\interview\gulpfile.ts:1
(function (exports, require, module, __filename, __dirname) { import * as gulp f rom 'gulp';
^^^^^^
SyntaxError: Unexpected token import
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 Liftoff.handleArguments (C:\Users\admin\AppData\Roaming\npm\node_modules\gu lp\bin\gulp.js:116:3)
There are 3 things you need to do to make gulp work with ES6 imports:
Rename gulpfile.js to gulpfile.babel.js
Run this command:
npm i #babel/preset-env #babel/register -D
Add a .babelrc file to the root folder of your project with the following code in it:
{
"presets": [
"#babel/preset-env"
]
}
You should now be able to use ES6 imports in your Gulp files.
Note: if you want to use TypeScript in your Gulp files instead, you should follow the steps outlined here:
https://stackoverflow.com/a/49849088/1611058
1) Create a ".babelrc" file in your Projekt folder (where also all your other config files are)
Code (.babelrc)
{
"presets": ["es2015"]
}
2) Setup/Install the Babel in your NPM (see https://babeljs.io/setup). E. g. with Node:
npm install babel-preset-env --save-dev
OS: Windows 7 64-bit
Need to do parsing xml-file using Node.js.
Using a library for parsing xml2js.
Xml2js installed using the command "npm install xml2js".
However, if you run the code:
var fs = require ('fs'), xml2js = require ('xml2js');
var parser = new xml2js.Parser ();
fs.readFile ('<path to the xml-file>', function (err, data) {
parser.parseString (data, function (err, result) {
console.dir (result);
console.log ('Done');
});
});
an error:
module.js:340
throw err;
^
Error: Cannot find module 'xml2js'
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> (<путь до js-файла>:3:14)
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)
Tell me, please, how to solve the problem?
I was also facing the same issue. Here's what I did:
Install the module using following:
$ npm install -g *module_name*
Then go to any parent dir of your project dir (it can be project dir itself) and run the following command:
$ npm link *module_name*
Make sure that the directory ./node_modules/xml2js exists.
When you run npm install somemodule at D:/test, it will be stored to D:/test/node_modules/somemodule, then you can require this module in D:/test/*.js, and you can not require it at D:/other/place/*.js. If you hope the module can be required anywhere you should run:
npm install somemodule -g
I had a similar issue and even tried the fix mentioned by Lellansin, but it didnt help. There were some issues with npm cache and I had to clear it using the command:
npm cache clean
And it worked for me.