1

I tried to run this example on my ubuntu os.

https://github.com/google/zx/blob/main/examples/basics.mjs

after I installed zx from npm

via npm i -g zx

and run the following cmd:

sudo zx ./script.mjs

i got below error:

    /usr/local/lib/node_modules/zx/zx.mjs:17
    import {basename, dirname, extname, join, parse, resolve} from 'path'
           ^
    
    SyntaxError: Unexpected token {
        at Module._compile (internal/modules/cjs/loader.js:723:23)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
        at Module.load (internal/modules/cjs/loader.js:653:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
        at Function.Module._load (internal/modules/cjs/loader.js:585:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
        at startup (internal/bootstrap/node.js:283:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

My npm version is : 7.14.0

kevinnls
  • 728
  • 4
  • 19
dcas
  • 111
  • 1
  • 10
  • an aside: you didn't need sudo. as for the error itself, i could not replicate it. what's your `zx` version? check with `zx -V`. mine was **1.14.0**. were there any errors during installation of `zx`? try a reinstall just in case `npm -g rm zx && npm -g i zx` – kevinnls May 27 '21 at 16:00
  • I tried to reinstall ( i needed to use sudo ) as you said above. When i tried to run zx -v i got bellow output. https://gist.github.com/casdidier/9fa27a33bf7607fe54b1e8e5a7acc946 – dcas May 31 '21 at 12:11
  • capital V `zx -V`. sudo for installing things ; sudo for testing scripts (generally) – kevinnls May 31 '21 at 16:58
  • okay. i just checked. -V and -v are synonymous. so the problem is elsewhere. i am not sure where – kevinnls May 31 '21 at 17:09
  • were there any error messages during or after installation? – kevinnls May 31 '21 at 17:16
  • Indeed my node version was too old v10,19.0 I updated to v.14.17.0 My node was not supporting import ( https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import ) Now it works fine ! – dcas Jun 01 '21 at 15:58
  • aha! glad you figured it out. :) i recommend answering your own question and marking as accepted. it'll be helpful for others who come across the same problem in the future – kevinnls Jun 02 '21 at 04:32

1 Answers1

1

As exlained in above comments:

The issue originated from an old version node that didn't recognize the import feature. which is available only since : v13+ ( see https://stackoverflow.com/questions/39436322/node-js-syntaxerror-unexpected-token-import)

dcas
  • 111
  • 1
  • 10