n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.18k stars 187 forks source link

Noob question: `Cannot use import statement outside a module` when trying to use an external module #239

Closed brunetton closed 3 years ago

brunetton commented 3 years ago

Hi

Sorry for this noob question but I'm kind of stuck here: is it possible to import external node modules ?

I tried to install and use a node module, but trying to import it on ijsnotebook:

> import { Gitlab } from '@gitbeaker/node';

evalmachine.<anonymous>:1
import { Gitlab } from '@gitbeaker/node';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at new Script (vm.js:100:7)
    at createScript (vm.js:261:10)
    at Object.runInThisContext (vm.js:309:10)
    at run ([eval]:1054:15)
    at onRunRequest ([eval]:888:18)
    at onMessage ([eval]:848:13)
    at process.emit (events.js:315:20)
    at emit (internal/child_process.js:903:12)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)

I surely missed something but this could be useful for others

n-riesco commented 3 years ago

The error you see is the same error you'd see if you try to run import in a Node.js CLI session. For more info, see related issues: #210 #213 #215

Alternatives to a static import:

Closing as duplicate of #210

brunetton commented 3 years ago

Thanks for your answer and sorry for the noise

prothSFDC commented 1 year ago

THANK YOU @n-riesco for looking into this I saw your comment here: https://github.com/n-riesco/ijavascript/issues/210#issuecomment-1458474048

I was nearly giddy with having a recent version of d3 working.

I'll keep testing, but it gave hope that it isn't insurmountable