Search code examples
node.jsnpmecmascript-6ckeditor

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


Solution

  • 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/