-
Notifications
You must be signed in to change notification settings - Fork 184
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
Error using import
#210
Comments
Your experience with ES6 modules depends on your Node version. I've just tested the REPL in the current version (v13.9.0) and this is the error Node throws:
And for example, I'm able to reproduce the error message you get, using Node v10:
|
import
I've looked through this issue and some of the related ones, but I wasn't able to find a solution for this. Is enabling ECMAScript modules supported by ijavascript for use in Jupyter Notebooks? I tried setting |
Last time I checked (node.js v14.13.0), the REPL doesn't support this use yet. It fails with:
|
Re I haven't seen any activity in standard-things/esm#886 , |
The issue is not related to the extension used for a module. I wouldn't expect the use of |
From #239, alternatives to a static import:
|
Hi @n-riesco - I've tried using the suggestions provided above (like from 239, or the related ones that mentions) Might you have any other thoughts we could try?
|
Hi @prothSFDC I'm sorry it took me so long to come back to you. It's been hard to find chunks of time long enough to look into this. These are the options I've looked into so far:
I've opened nodejs/node#40898 with nodejs re I'm not familiar with |
check out: Name: Node.js Notebooks (REPL) https://github.com/DonJayamanne/typescript-notebook It appears to be using runInNewContext and can do imports |
For the time being I am using https://github.com/DonJayamanne/typescript-notebook (very well done) but I would prefer to use Jupyter as I would like to share notebooks with non-developers who aren't running vs-code. Without import I am not sure how I would use the redis npm which my project depends on. If I've missed a work-around please let me know. Otherwise, I'll be watching this space. |
@disarticulate apologies for the late reply (somehow I missed your message). I had a look at # ts-node
> import d3 from "d3"
undefined
> d3
node:internal/modules/cjs/loader:1210
throw err;
^
Uncaught:
Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/d3/src/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
at require.extensions.<computed> [as .js] (/usr/local/lib/node_modules/ts-node/dist/index.js:851:20)
at /usr/local/lib/<repl>.ts:1:30
at Script.runInThisContext (node:vm:129:12)
at runInContext (/usr/local/lib/node_modules/ts-node/dist/repl.js:466:23)
at Object.execCommand (/usr/local/lib/node_modules/ts-node/dist/repl.js:434:36)
at /usr/local/lib/node_modules/ts-node/dist/repl.js:456:48
at Array.reduce (<anonymous>)
at appendCompileAndEvalInput (/usr/local/lib/node_modules/ts-node/dist/repl.js:456:29)
at evalCodeInternal (/usr/local/lib/node_modules/ts-node/dist/repl.js:117:16)
at REPLServer.nodeEval (/usr/local/lib/node_modules/ts-node/dist/repl.js:132:32)
at bound (node:domain:433:15)
at REPLServer.runBound [as eval] (node:domain:444:12)
at REPLServer.onLine (node:repl:902:10)
at REPLServer.emit (node:events:525:35)
at REPLServer.emit (node:domain:489:12)
at REPLServer.self._ttyWrite (node:repl:997:9)
at ReadStream.emit (node:events:513:28)
at ReadStream.emit (node:domain:489:12)
at emitKeys.next (<anonymous>)
at ReadStream.emit (node:events:513:28)
at ReadStream.emit (node:domain:489:12) {
code: 'ERR_REQUIRE_ESM'
} BTW, the reason iJavasScript is using |
For those interested in using ES modules in iJavaScript: I've been able to do so using esm-hook and a recent version of node.js (failed with v12, worked with v18): # cat test.mjs
const test = "test";
export default test;
# node
Welcome to Node.js v18.12.1.
Type ".help" for more information.
> require("esm-hook")
[Function (anonymous)]
> var test1 = require("./test.mjs").default; test1
'test'
> vm.runInThisContext("var test2 = require('./test.mjs').default; test2")
'test' |
Flag |
The text was updated successfully, but these errors were encountered: