Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: NodeAPI npm version 9.0.2, nodejs 10.13.0 "import chef" -> SyntaxError: Unexpected identifier #605

Closed
fletcher2 opened this issue Jul 26, 2019 · 3 comments · May be fixed by masifpak/CyberChef#7, Croat79/CyberChef#8 or Centaurioun/CyberChef#33
Labels

Comments

@fletcher2
Copy link

Describe the bug

node <<<'import chef from "cyberchef";'
[stdin]:1
import chef from "cyberchef";
       ^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Object.<anonymous> ([stdin]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at evalScript (internal/bootstrap/node.js:582:27)
    at ReadStream.<anonymous> (internal/bootstrap/node.js:325:15)
    at ReadStream.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
node -v
v10.13.0
npm info cyberchef

cyberchef@9.0.2 | Apache-2.0 | deps: 66 | versions: 202
...
@fletcher2 fletcher2 added the bug label Jul 26, 2019
@d98762625
Copy link
Member

What's the use case here? I've only tested imports with .mjs extension files and the --experimental-modules flag for v10.x.x:

node --experimental-modules filename.mjs

@madelaine2
Copy link

He's just following the wiki article for Node API:
https://github.com/gchq/CyberChef/wiki/Node-API

Decode a Base64 encoded-string

import chef from "cyberchef";

chef.fromBase64("U28gbG9uZyBhbmQgdGhhbmtzIGZvciBhbGwgdGhlIGZpc2gu").toString();

That merely seems to be wrong usage?

nvm install 10.13
node --experimental-modules 
> (node:20277) ExperimentalWarning: The ESM module loader is experimental.
> import chef from "cyberchef";
import chef from "cyberchef";
       ^^^^

SyntaxError: Unexpected identifier

@d98762625
Copy link
Member

Ah apologies, I didn't make it clear that all those snippets are to be run inside .js or .mjs files (depending on whether you use import or require).

A working example of that snippet you have is:

// inside test.mjs
import chef from "cyberchef"
console.log(chef.fromBase64("U28gbG9uZyBhbmQgdGhhbmtzIGZvciBhbGwgdGhlIGZpc2gu"))

Then to make the environment to run it:

mkdir new-project && cd new-project
npm init // yes to all defaults
npm install --save cyberchef
// create test.mjs with above content. Then:
node --experimental-modules test.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment