ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

SyntaxError: Unexpected token with Node 11.4.0.

Open blfuentes opened this issue 7 years ago • 3 comments

After updating to the new Node version 11.4.0 I get SyntaxError: Unexpected token for some very simple code...

Node: 11.4.0 Typescript: 3.2.2 ts-node: 7.0.1 SO Version: Windows 10 1809 [10.0.17763.107]

Example https://github.com/blfuentes/testvscode https://github.com/Microsoft/vscode/issues/64693

Works:

tsc

node .\test.js

Fails: node .\test.ts --nolazy -r ts-node/register

(function (exports, require, module, __filename, __dirname) { let mystring: string = "mytest";
                                                                          ^

SyntaxError: Unexpected token :
    at new Script (vm.js:83:7)
    at createScript (vm.js:267:10)
    at Object.runInThisContext (vm.js:319:10)
    at Module._compile (internal/modules/cjs/loader.js:686:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:776:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)`

With another example with a simple import { ModuleName } from "./ModuleName" it raises similar error:

 import { MarbleNode } from "../MarbleNode";
        ^

 SyntaxError: Unexpected token {

blfuentes avatar Dec 10 '18 07:12 blfuentes

You aren’t using ts-node in these examples. Node.js flags need to go before the script.

blakeembrey avatar Dec 10 '18 16:12 blakeembrey

You aren’t using ts-node in these examples. Node.js flags need to go before the script.

I have been using the same launch.json config for a long time and it stopped working after I updated to the version 11.4.0.

https://github.com/Microsoft/vscode/issues/64693

Could you please point me the problem?

blfuentes avatar Dec 10 '18 18:12 blfuentes

I am using a similar launch.json we have in this github. I modified to make it look like this and it works. Difference is I send the ${workspaceRoot} within the args and no longer using cwd. Could it be the new node version has any problems to resolve it?

Generated command is still the same:

Node 11.3.0 (works)

C:\Program Files\nodejs\node.exe --nolazy -r ts-node/register --inspect-brk=22234 test.ts Debugger listening on ws://127.0.0.1:22234/c6c4c4cb-5af8-477f-a4d3-7ae7cf1931d6

Node 11.4.0 (old launch.json not working)

C:\Program Files\nodejs\node.exe --nolazy -r ts-node/register --inspect-brk=40666 test.ts Debugger listening on ws://127.0.0.1:40666/bae735eb-e51d-4930-aab4-329c1066fa92

Works in 11.4.0-->

C:\Program Files\nodejs\node.exe --nolazy -r ts-node/register --inspect-brk=36677 C:\Users\insan\source\repos\test/test.ts Debugger listening on ws://127.0.0.1:36677/6c886e43-efea-4744-9e9b-deb07c1f39c1

{
    "name": "Launch Program 2",
    "type": "node",
    "request": "launch",
    "runtimeArgs": [
        "--nolazy",
        "-r",
        "ts-node/register"
    ],
    "args": [
        "${workspaceRoot}/${relativeFile}"
    ],
    "protocol": "inspector",
}

blfuentes avatar Dec 10 '18 19:12 blfuentes