Skip to content
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

for ES6+ module settings, REPL error on first command: Unexpected token 'export' #1902

Closed
yilmazdurmaz opened this issue Oct 23, 2022 · 3 comments · Fixed by #1959
Closed

Comments

@yilmazdurmaz
Copy link

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?:
@cspotcode
Copy link
Collaborator

Seems related to #1752

@yilmazdurmaz
Copy link
Author

Seems related to #1752

I cannot say if it is so. You know its content better and way better than I to relate 😅

But I tested and having "type":"module" in "package.json" file does not give this error I got. It seems it needs "tsconfig.json"

@wvhulle
Copy link

wvhulle commented Dec 20, 2022

What is the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants