for ES6+ module settings, REPL error on first command: Unexpected token 'export'
#1902
Closed
Description
Search Terms
REPL
Unexpected token 'export'
#1563 has it, describes wrong, closed with no fix.
Expected Behavior
When ts-node starts with ES6+ module types, it behaves as usual as pre-ES6 module types, which is having a smooth "undefined" message upon pressing "enter" key the first time with an empty line or having some result if there is an actual command.
Actual Behavior
When ts-node starts with ES6+ module types, the first line results in an error whether full or empty (empty line gives ...<repl>.ts:2
)
c:\Workspace\test>npx ts-node
> console.log("hello") <===== first command results in error
c:\Workspace\test\<repl>.ts:3
export {};
^^^^^^
Uncaught SyntaxError: Unexpected token 'export'
> console.log("hello") <===== later commands do not seem to have the problem
hello
undefined
>
Steps to reproduce the problem
- create an empty folder, open a terminal and invoke
npm install ts-node
- create a new
tsconfig.json
with the following content
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "NodeNext"
}
- start REPL with
npx ts-node
- just press enter or try some command if you want. the first press on "enter" will result in this error
Minimal reproduction
above are the minimal steps
Specifications
ts-node v10.9.1
node v18.9.0
compiler v4.8.4
- ts-node version:
- node version:
- TypeScript version:
- tsconfig.json, if you're using one:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "NodeNext"
}
}
- package.json: (having
"type":"module"
has no effect)
{
"dependencies": {
"ts-node": "^10.9.1"
}
}
- Operating system and version: Windows 10 21H2
- If Windows, are you using WSL or WSL2?:
Metadata
Assignees
Labels
No labels