I'm trying to use arrow functions in node v0.10.33 under Ubuntu 14.04 (I'm running node with --harmony flag), but I'm getting this error:
console.log( [1,2,3,4].map(x => x*x) );
^
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
This should work now in node v0.12.x, with the --harmony flag. Also note that you can get arrow functions in node using the babel package.
http://babeljs.io/docs/using-babel/
UPDATE:
As correctly indicated by Mike 'Pomax' Kamermans, the --harmony flag is not required when using Node.js >= 4.x. Please see https://nodejs.org/en/docs/es6/ for more information on the status of ES6 support in Node.js.
Node, even with the harmony flag, doesn't support the fat arrow yet. Source.
Edit: Fun little fact, ES6 support is one of the reasons Node got forked into io.js. Check out their page on ES6 features - they provide a flag for the arrow functions, but discourage using it.
Related
I want to use Ionic V1.X, since I want to use AngularJS with .js support, instead of Angular with .ts support.
But when I try to run "ionic -v" to see my ionic version it prints out:
ReferenceError: primordials is not defined
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\tubes\AppData\Roaming\npm\node_modules\ionic\node_modules\vinyl-fs\node_modules
aceful-fs\graceful-fs.js:3:27)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
I deinstalled my previous ionic version to reinstall the old one.
I saw online that I could need an older node.js version, but I cannot find which one is needed.
my actual node.js is v12.19.0
Ok, I tried out different node.js
node.js V.6.12.3 seems to work, for anyone who might encounter the same problem
I'm running nativescript on an ubuntu server and I have an issue when I run tns build android.
/home/nativescript/sample-Groceries/platforms/android/build-tools/check-v8-dependants.js:3
let args = process.argv;
^^^
SyntaxError: Unexpected strict mode reserved word
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 Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
I heve those versions installed:
npm 1.3.10
node v0.10.25
I know that "let" keywords are part of ES6, but how can I fix this issue?
Thank you!
You need to upgrade your node version. For decent ES6 support; you really want a minimum of Node 4.x with the harmony flags. Technically, If you use the harmony flag, then earlier versions of Node can use the "let" command. But support before v4 was not great.
For really good support without having to use the harmony flags; the current LTS (6.9.x) has very good support for ES6 functionality.
One thing this error is signifying that the file does not have a "use strict"; in it; so unless you want to manually change that file, you may be just want to use the current LTS Node 6.9.x (or later); as it no longer requires the "use strict"; to use ES6 functionaliy.
I try to run server: node app.js on Ubuntu 14.04 LTS then get this error:
/home/ubuntu/Ytutor_Server/node_modules/mongodb-core/lib/topologies/shared.js:18
var nodejsversion = f('Node.js %s, %s', process.version, os.endianness());
^
TypeError: Object #<Object> has no method 'endianness'
at Object.<anonymous> (/home/ubuntu/Ytutor_Server/node_modules/mongodb-core/lib/topologies/shared.js:18:61)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/ubuntu/Ytutor_Server/node_modules/mongodb-core/lib/connection/pool.js:11:12)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
I have no idea what's wrong with this. I use Nodejs v6.9 and Mongodb v3.2.11, it should have module os that content 'endianness'?
The issue is that an older version of node is being used to run the script(s) (pre-v0.10 in this case). os.endianness() was added in node v0.10.0 (technically v0.9.x).
The reason for separate node and nodejs binaries on Linux is that some distributions (namely Debian-based) do that to avoid a conflict in package names. Before node.js, the 'node' package name was already being used by an amateur radio package, so when node.js became officially packaged by Debian they chose a different name ('nodejs') rather than replace the existing 'node' package. To also confuse things further, both packages use the same binary names, so that also had to be changed to avoid any potential confusion. This does present some problems though for shebangs that assume the node binary name.
Since most developers do not use the 'node' amateur radio package, one popular solution to the whole node/nodejs naming issue is to simply use a third-party repository (such as NodeSource's) that not only provides the latest versions of node but they also use the 'node' binary name in their packages.
I'm trying to run an example, but I'm getting the following error when I try to gulp. I'm pretty new to node, so any direction or help would be very appreciated. The install went without any issues, seemingly.
$ nvm exec 4.2.2 gulp
Running node v4.2.2 (npm v2.14.7)
util.js:756
throw new TypeError('The super constructor to `inherits` must not ' +
^
TypeError: The super constructor to `inherits` must not be null or undefined.
at Object.exports.inherits (util.js:756:11)
at Object.<anonymous> ([working directory path]/node_modules/browser-sync/node_modules/http-proxy/lib/http-proxy/index.js:108:17)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> ([working directory path]/node_modules/browser-sync/node_modules/http-proxy/lib/http-proxy.js:4:17)
at Module._compile (module.js:435:26)
It seems this issue has come up in different contexts before but was unanswered:
1) Mean.io application is throwing error with forever
2) https://github.com/rajaraodv/rabbitpubsub/issues/4
Seems to be a fairly recent issue and it seems to not have to do with http-proxy.
Turned out to be a problem with an older version of browser-sync. Once that was updated, this started to work.
Try an older version of Node. The example's package.json specifies Node 0.10 in the engines section, which suggests the initial code may have been written for that version.
I'm new to Node.js. I have node 0.9.5-pre running on Linux Mint. I used npm (1.1.70) to install TypeScript but now I get the following error when I run tsc:
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
at Function.Object.defineProperty.get (module.js:386:11)
at Object.<anonymous> (/home/rolyp/bin/tsc#0.8.0:4:21)
at Module._compile (module.js:454:26)
at Object.Module._extensions..js (module.js:472:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:497:10)
at process._tickCallback (node.js:334:13)
I gather that require.paths is not supported in recent versions of Node. There seem to be several relevant existing questions, but I don't understand the problem well enough to make use of the answers.
I tried deleting ~/.node_modules, but that didn't help.
Could someone please explain the problem and point me to a solution?
thanks
I have node 0.9.5-pre
Was a bug in the beta release that was fixed when 0.9 official came out