Nativescript error on build - node.js

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.

Related

Use ES6 with npm in CLI mode

I am trying to get CKEditor in my project with a custom build.
However, my problem is more general, so feel free to answer even if you don't use CKEditor.
Following the instructions to generate a custom build, I am getting a syntax error when running npm run build in terminal:
my/build/path/bin/create-entry-file.js:12
const { bundler } = require('#ckeditor/ckeditor5-dev-utils');
^
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 Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
Npm fails with a bunch of text and the above error. I believe this error is generated due to modern ECMAScript syntax, which is not recognized in my local machine.
However, the build I am trying to generate is there, complete and ready. Also, some other documentation of theirs, indicate more import {...} from syntax. This means that they are able to generate the build without the need of external packages (otherwise they would be in the package.json dependencies).
So, my question is, how do I install the software needed that will allow my npm to recognize and execute modern ES syntax ?
I am running on Ubuntu 16, with the lastest npm version: 5.6.0.
Thanks in advance, let me know if I can provide more information
Can you please check the version of Node on your computer?
Run in the terminal
node -v
You need to have at least 6.4 as your Node.js version according to this list on your computer
Here you have a link where you get and update to the newest version of Node 8.9.4 for different platforms. In your case check Linux
https://nodejs.org/en/download/

A module does not compile in a newer node.js version, any workarounds?

my open-source project depends on a lemmatization module —
https://github.com/grachev/node-lemmer
— which needs to be compiled before it can run.
After updating to a newer version of node.js I can't run this module, because it needs to be re-compiled. Usually this was done when I simply did npm install node-lemmer however it is now not available in npm and I don't know how to compile it under that new node version and why I have to do it at all...
I tried running npm rebuild but it does not recompile – too many errors. The issues folder of that project on GitHub has the issue up already but there's no fix for it...
What could I do about it? Why do I need to recompile this module when I install a new version of node? Is there a workaround? Could I "trick" node or that module so it doesn't need to recompile? Or maybe it's possible to compile it manually?
...
Some mode details:
I used to run my project on node 0.8.3 vesion and then switched to the new 8.8.0 version. Now when I try to run my project under the new node version it doesn't start giving the following error:
module.js:641
return process.dlopen(module, path._makeLong(filename));
^
Error: Module did not self-register.
at Object.Module._extensions..node (module.js:641:18)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at Function.Module._load (module.js:486:3)
at Module.require (module.js:556:17)
at require (internal/module.js:11:18)
at Object.<anonymous>
(/path-to-my-project/node_modules/node-lemmer/lib/node-lemmer.js:1:82)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
which is an error I've seen before because my module could not be compiled.
my project is https://github.com/noduslabs/infranodus in case it helps to see the source code.

Nodejs: TypeError: Object #<Object> has no method 'endianness'

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.

Arrow functions not working in node --harmony under Ubuntu

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.

"require.paths is removed" error running TypeScript compiler on Linux Mint

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

Resources