Open perplexes opened 5 years ago
:load
gives the same error
Having the same error here:
$ tsun
TSUN : TypeScript Upgraded Node
type in TypeScript expression to evaluate
type :help for commands in repl
> import fs from 'fs'
evalmachine.<anonymous>:3
Object.defineProperty(exports, "__esModule", { value: true });
^
ReferenceError: exports is not defined
at evalmachine.<anonymous>:3:23
at Script.runInContext (vm.js:135:20)
at Object.runInContext (vm.js:298:6)
at startEvaluate (/usr/local/lib/node_modules/tsun/bin/src/repl.js:147:25)
at replLoop (/usr/local/lib/node_modules/tsun/bin/src/repl.js:173:9)
at /usr/local/lib/node_modules/tsun/bin/src/repl.js:311:9
at Interface._onLine (readline.js:305:5)
at Interface._line (readline.js:680:8)
at Interface._ttyWrite (readline.js:960:14)
at ReadStream.onkeypress (readline.js:183:10)
>
this makes any module with an import statement unusable in tsun for me
I'm having the same issue
% pnpm i -D typescript @types/node tsun
% tsun
node:internal/fs/utils:346
throw err;
^
Apply that workaround....
% pushd xxx/tsun1/node_modules/.pnpm/tsun@0.5.1_typescript@4.9.5/node_modules/tsun/node_modules
xxx/tsun1/node_modules/.pnpm/tsun@0.5.1_typescript@4.9.5/node_modules/tsun/node_modules xxx/tsun1
% ln -s ../../@types .
% popd
% cat foo.ts
import bar from './bar'
export function foo():string { return bar() }
% cat bar.ts
export default function bar():string { return "bar says foo!" }
% tsun
TSUN : TypeScript Upgraded Node
type in TypeScript expression to evaluate
type :help for commands in repl
> :help
tsun repl commands
:type symbol print the type of an identifier
:doc symbol print the documentation for an identifier
:clear clear all the code
:print print code input so far
:help print this manual
:paste enter paste mode
:load filename source typescript file in current context
> :load foo.ts
% pnpm i -D zx
% zx --repl
❯ .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.editor Enter editor mode
.exit Exit the REPL
.help Print this help message
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file
Press Ctrl+C to abort current expression, Ctrl+D to exit the REPL
❯ .load foo.ts
import bar from './bar'
export function foo():string { return bar() }
❯ foo()
import bar from './bar'
^^^^^^
Uncaught:
SyntaxError: Cannot use import statement inside the Node.js REPL, alternatively use dynamic import
❯
% pnpm i -D ts-node
% ts-node
> .load foo.ts
import bar from './bar'
export function foo():string { return bar() }
> foo()
'bar says foo!'
>
%