Use ES6 with npm in CLI mode - node.js

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/

Related

Node "Error: Cannot find module 'node:process'" when using global fastify-cli (mac)

I'm setting up a new mac dev machine, and have gotten node, npm, and nvm installed. All seems fine within a single project directory. However, when trying to install and use fastify-cli, I'm receiving an error:
internal/modules/cjs/loader.js:892
throw err;
^
Error: Cannot find module 'node:process'
Require stack:
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js
- /Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Function.Module._load (internal/modules/cjs/loader.js:745:27)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs:3:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/marked-terminal/index.cjs',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/lib/widget/markdown.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/node_modules/blessed-contrib/index.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/docs.js',
'/Users/a/.nvm/versions/node/v14.17.5/lib/node_modules/fastify-cli/cli.js'
]
}
Steps to reproduce:
$ npm install --global fastify-cli (succeeds)
$ fastify generate myproject (also produces above error)
$ fastify (also produces above error)
This likely doesn't have much to do with fastify. It seems to me that the global package is not finding Node for some reason, but I may be wrong.
I'm using zshell
I've got xcode installed
I've upgraded the version of node i'm using
I'm able to start a fastify app from the app directory directly/without using the generator
Any thoughts?
I fixed the error following the answer in this GitHub issue reply
node internal syntax (e.g.: node:<core_module_name>) is not supported by Node.js 14.16.0
The CLI needs node version >= 14.19
Steps:
Upgrade node using nvm to 14.9.0 (the last lts in 14.x).
Set default version 14.9.0 or above.
you need to run
npm i #types/node
I solved it by switching the current user to a root user.
If you are using a Mac, try to switch to a root user account and do the same thing again.
I assigned my previous account as 'administrator' under system preferences, but this won't solve the issue. The problem was perfectly solved when I switched to my primary account.
Hope this could help!

Facing Issue with Node-Sass within Node Program

From Command Prompt I am able to execute node-sass and convert scss to css
D:\> node-sass test.scss testout.css
works and works correctly.
But...
When I am writing a program in electron ( need to dynamically convert a scss string to css string )
var sass = require('node-sass');
var output = sass.renderSync({
data: Some_SCSS_Content
});
I get an error as below:
(node:96852) UnhandledPromiseRejectionWarning: Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (80)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.9.4
at module.exports (D:\OASDEV\electron-quick-start\node_modules\node-sass\lib\binding.js:13:13)
at Object.<anonymous> (D:\OASDEV\electron-quick-start\node_modules\node-sass\lib\index.js:14:35)
at Module._compile (internal/modules/cjs/loader.js:967:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1004:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module._load (electron/js2c/asar.js:769:28)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
On searching I found that this might be due to compatibility issues with Node Version.
Ref: Error: Node Sass does not yet support your current environment: Windows 64-bit with false
I have Node 10.18.1 and Node-sass version 4.9.4. They are compatible.
Further on I tried rebuild
npm rebuild node-sass
But that did not work either.
Another I tried changing version of Node-sass , tried 4.14 and 4.12 also.
It really stumps me that why it works from terminal and not in another Node program.
Node-sass doesn't currently support running in Electron. They are both V8 based runtimes, but have different ABI versions from NodeJs. Support might be added in v5 of node-sass

NativeScript Angular installation: Unexpected token { error

I followed the NativeScript installation guide here:
https://docs.nativescript.org/angular/start/quick-setup
I finished all 3 steps, but when I ran "tns doctor" at the end, I got these issues:
Support for Node.js ^4.0.0 is deprecated and will be removed in the next release of NativeScript. Please, upgrade to the latest Node.js LTS version.
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 Yok.resolveDependency (C:\Program Files (x86)\Nodist\bin\node_modules\nativescript\lib\common\yok.js:338:13)
at Yok.resolveByName (C:\Program Files (x86)\Nodist\bin\node_modules\nativescript\lib\common\yok.js:315:31)
at Yok.resolve (C:\Program Files (x86)\Nodist\bin\node_modules\nativescript\lib\common\yok.js:262:25)
Error while reporting exception: SyntaxError: Unexpected token {
When I tried to resolve the first issue, I ran "nodist -v" and it told me I'm on version 0.8.8. So I ran "nodist use 8" and then "nodist list" and I'm on 8.11.1. So when I run "nodist -v" again, I expect it to say 8.11.1 but it spits out 0.8.8 again.
I checked the error files listed in the syntax error and they are syntactically correct.
How do I resolve these issues?
The Nodist library looks abandoned and I'm not sure what might be the reason to interfere with NativeScript. We certainly haven't tested it.
My suggestion would be to remove it from your system and ensure that you have Node.JS LTS properly installed. If you need to work with multiple version of Node on your system, I recommend you to try nvm - we don't have known issues when using NativeScript with nvm.

Installing node-sass on IBM i (formerly iSeries/ AS/400)

Has anyone been able to successfully install node-sass on IBM i?
I'm currently running Node 6.9.1, and am able to install many npm packages. However, the #angular/cli has a dependency on node-sass, and apparently, node-sass has a compiled component that is giving me grief to install.
My first issue had to do with being able to download the binary itself - because of our network setup, the IBM i was unable to download the binary from:
https://github.com/sass/node-sass/releases/download/v4.5.2/aix-ppc-48_binding.node
I was getting a timeout error. I was able to resolve that by changing the SASS_BINARY_SITE to the non-https version:
export SASS_BINARY_SITE='http://github.com/sass/node-sass/releases/download'
However, now, even though the binary downloads successfully, i get the following error when npm tries to test the binary:
Testing binary Binary has a problem: Error: Could not load module
/QOpenSys/QIBM/ProdData/OPS/Node6/lib/node_modules/node-sass/vendor/aix-ppc-48/binding.node.
The module has an invalid magic number.
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
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 module.exports (/QOpenSys/QIBM/ProdData/OPS/Node6/lib/node_modules/node-sass/lib/binding.js:19:10)
at Object.<anonymous> (/QOpenSys/QIBM/ProdData/OPS/Node6/lib/node_modules/node-sass/lib/index.js:14:35)
And then npm tries to build the binary locally, but fails because Python2 isn't available on this machine. I can request the installation of Python2, which is a long process in our environment, but before i continue down that rabbit hole, I'd like to know if it's actually possible to have node-sass working, and if so, is there another binary that i can point the npm install at to use instead.
Or, is there an alternative means of get node-sass working?
As of 2017 this will likely not be possible. In addition to Python you will need the entire cpp toolchain to build node and node addons. Since this is already a very hard requirement for desktop PCs, systems like that will have a even harder time. Judging from their binding.gyp, there is just support for OS X, Windows and Linux.
node-sass is known to be hard to build also across the node use base.
Very likely you rather want to have a build / CI step on Linux that compiles your SASS files and builds your artefact.

Creating a dev environment from existing website with nodejs

So I've used Node.js in the past before, but I've never created a development environment from a pre-existing website. And now I have to. Plus, the previous developer worked in another state and used an iMac and developed in Coda. We were able to get all the files to my current workspace but I am trying to create the project in Visual Studio with Node Tools and am running into an issue. I fairly certain that its some kind of routing/config/setup issue but have not been able to suss it out and I've been rooting through package.json and config files for days.
All files are in the same relative directory from the root yet, and I've updated all packages and adjusted the code accordingly (I believe for the updated packages). However, when I try to start the site up, I run into this issue.
Debugger listening on [::]:5858
T:\IT\Website\ComfortCo(Dev)\ComfortCo(Dev)\views\index.jade:1
(function (exports, require, module, __filename, __dirname) { extends global_layout
^^^^^^^
SyntaxError: Unexpected token extends
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 Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
Press any key to continue...
The site uses jade with express and this is a pretty basic function of jade layouts. So I do not know why there is a Syntax Error.
Any ideas?
Update
So I was told that I did not have the most up-to-date versions of Node except I installed the most current version of Node when I installed Node Tools for VS and the pathing is correct.
However, when I ran npm list and npm list -g they came back with nothing even though my projects npm repository shows a whole list of packages installed and up-to-date. So I can only conclude that their is some pathing issue here. However, I have never configured Node paths. I've always just left them default. Any guidance here?
The extends keyword is supported since Node version 4.x - see:
http://node.green/#ES2015-functions-class-extends
It seems that you may be running an older version of Node but of course it's hard to tell because you provided no information about your runtime environment whatsoever.

Resources