It is possible in Node.js v14, but you need to use the import operator, rather than the import declaration.

$ node

Welcome to Node.js v14.4.0.
Type ".help" for more information.
> let myModule;
undefined
> import("./my-module.js").then(module => { myModule = module });
Promise { <pending> }
> myModule.foo();
"bar"
Answer from diachedelic on Stack Overflow
🌐
GitHub
github.com › nodejs › node › issues › 48084
REPL: import statement inside the Node.js REPL · Issue #48084 · nodejs/node
May 20, 2023 - Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import Instead of: import assert from 'node: assert' use: const assert = await import('node: assert')
Published   May 20, 2023
🌐
Stack Exchange
ethereum.stackexchange.com › questions › 114221 › where-do-i-place-the-code-from-the-uniswap-tutorial
hardhat - Where do I place the code from the Uniswap tutorial? - Ethereum Stack Exchange
$ npx hardhat console Welcome to Node.js v16.13.0. Type ".help" for more information. > import { ethers } from "ethers"; import { ethers } from "ethers"; ^^^^^^ Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
🌐
Michael Currin
michaelcurrin.github.io › dev-cheatsheets › cheatsheets › javascript › general › modules › dynamic-modules.html
Dynamic modules | Dev Cheatsheets
import fs from 'fs'; ^^^^^^ Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
🌐
GitHub
github.com › privatenumber › tsx › issues › 471
static import not support in repl · Issue #471 · privatenumber/tsx
> import {parse} from 'path'; import ... alternatively use dynamic import: const { parse } = await import("path"); > > ts-node > import {parse} from 'path' undefined > parse [Function: parse] > I tested with non-repl environment, ...
🌐
GitHub
github.com › nodejs › node › issues › 19570
dynamic import can't be used in the REPL · Issue #19570 · nodejs/node
October 27, 2017 - > import('fs').then(console.log, console.log) Promise { <pending>, domain: Domain { domain: null, _events: { removeListener: [Function: updateExceptionCapture], newListener: [Function: updateExceptionCapture], error: [Function: debugDomainError] }, _eventsCount: 3, _maxListeners: undefined, members: [] } } > { TypeError [ERR_INVALID_URL]: Invalid URL: repl at onParseError (internal/url.js:226:17) at parse (internal/url.js:235:3) at new URL (internal/url.js:318:5) at normalizeReferrerURL (internal/process/esm_loader.js:18:10) at setImportModuleDynamicallyCallback (internal/process/esm_loader.js:51:37) at process._tickCallback (internal/process/next_tick.js:114:7) input: 'repl' }
Published   Mar 24, 2018
🌐
Dek Genius
dekgenius.com › script-code-example › 82949-cannot-use-import-statement-inside-the-node-js-repl-alternatively-use-dynamic-import.html
Example Javascript for Cannot use import statement inside the Node.js REPL, alternatively use dynamic import-82949
code example for javascript - Cannot use import statement inside the Node.js REPL, alternatively use dynamic import You can study and learn programming as you wish in the content of this website.
Find elsewhere
🌐
Archlinux
copyprogramming.com › t › import-statement-inside-the-nodejs-repl-alternatively-use-dynamic
Import Statement Inside The Nodejs Repl Alternatively Use Dynamic - CopyProgramming
Import Statement Inside The Nodejs Repl Alternatively Use Dynamic ... function, rather than the import statement., Dynamic import is supported in the REPL since Node.js 13., results in the following error: Uncaught SyntaxError: Cannot use import statement, Why can't Deno use import statement s outside of a module?, To import modules in Deno REPL, you can use dynamic import()
🌐
Hacker News
news.ycombinator.com › item
Exploring competitive features in Node.js v18 and v19 | Hacker News
February 4, 2022 - For the frontend, Vite works well, and NextJS if you're using React in particular · Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
🌐
Stack Overflow
stackoverflow.com › questions › linked › 58384179
Recently active linked questions - Page 2 - Stack Overflow
I'm trying to publish an npm package, when testing locally during an import of my package I get the following error : Uncaught: SyntaxError: Cannot use import statement inside the Node.js REPL, ...
🌐
GitHub
github.com › TypeStrong › ts-node › issues › 1924
REPL with ES modules · Issue #1924 · TypeStrong/ts-node
November 1, 2022 - $ npx ts-node-esm > 2+2 /Users/ckoncz/work/git/csaba/ts-node-esm-examples/<repl>.ts:3 export {}; ^^^^^^ Uncaught SyntaxError: Unexpected token 'export' > 2+2 4 > const u = await import('./Util') Uncaught: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
Published   Dec 09, 2022
🌐
GitHub
github.com › nodejs › node › issues › 30868
module: incorrect relative path for dynamic import in REPL · Issue #30868 · nodejs/node
September 13, 2019 - Version: 13.2.0 Platform: Windows Subsystem: modules With a file system containing project/module.mjs, and running the Node.js REPL from within the project folder: node > import('./module.mjs') gives the error - UnhandledPromiseRejection...
Published   Dec 09, 2019
🌐
YouTube
youtube.com › watch
Why can’t i just use “import” in Node.js - YouTube
Hey guys, so for this video we look into why using import statements in Node.js modules is so frustrating sometimes and how to get them to work. Also did you...
Published   October 21, 2023
🌐
Replit
ask.replit.com › t › import-problems › 23051
Import problems - Node JS
Python #88: Authenticate FinesseProperly using authentication to detect individual users using Repl Auth.
🌐
Replit
ask.replit.com › t › node-js-module-import-help › 106971
Node.js module import help?
Python #88: Authenticate FinesseProperly using authentication to detect individual users using Repl Auth.
🌐
Stack Overflow
stackoverflow.com › questions › 73073219 › ts-node-cant-use-dynamic-imports-or-import-statements-while-in-repl-or-eval-in
node.js - ts-node can't use dynamic imports or import statements while in repl or eval in the cli - Stack Overflow
import * as test from './src/test'; //works but then when I try to use 'test' it gives //SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
🌐
Quora
quora.com › How-can-I-fix-cannot-use-import-statement-outside-a-module
How to fix “cannot use import statement outside a module” - Quora
Answer (1 of 4): Javascript allows module scripts when using in HTML, they are different by the “type” attribute. Most “imports” are just linked normally with the “