TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.84k stars 534 forks source link

return new TSError(diagnosticText, diagnosticCodes) #1125

Closed SeanDez closed 3 years ago

SeanDez commented 3 years ago

Expected Behavior

VsCode runs debugger normally

Actual Behavior

Upon starting the debugger;

/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:500
    return new TSError(diagnosticText, diagnosticCodes)
           ^
node_modules/source-map-support/source-map-support.js:475
Process exited with code 1
TSError: ⨯ Unable to compile TypeScript:
src/authenticate/router.ts(45,1): error TS1128: Declaration or statement expected.

    at createTSError (/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:500:12)
    at reportTSError (/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:504:19)
    at getOutput (/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:739:36)
    at Object.compile (/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:955:32)
    at Module.m._compile (/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:1043:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/home/owner/cp/asanaTaskRepeaterBackend/node_modules/ts-node/src/index.ts:1046:12)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Steps to reproduce the problem

  1. Install ts-node 9.0.0 via npm
  2. Run a VsCode launch config with these exact settings:
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "pwa-node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**",
        "node_modules"
      ],    
      "runtimeArgs": [
        "-r",
        "ts-node/register",
        // "--no-cache"
      ],
      "args": [
          "${workspaceFolder}/src/server.ts"
      ]
    }
  ]
}

Minimal reproduction

See above.

Specifications

cspotcode commented 3 years ago
TSError: ⨯ Unable to compile TypeScript:
src/authenticate/router.ts(45,1): error TS1128: Declaration or statement expected.

This is a normal TypeScript error. ts-node uses the TypeScript compiler to check for syntactic and semantic errors. When the compiler returns errors, we throw them. This is intended behavior.

JontyyYang commented 2 years ago
TSError: ⨯ Unable to compile TypeScript:
src/authenticate/router.ts(45,1): error TS1128: Declaration or statement expected.

This is a normal TypeScript error. ts-node uses the TypeScript compiler to check for syntactic and semantic errors. When the compiler returns errors, we throw them. This is intended behavior.

I also encountered this problem, what I want to ask is, can ts-node execute ts file, can it only prompt for type errors without blocking

blakeembrey commented 2 years ago

From the docs, you can use --log-error.

AceCoderYoda commented 2 years ago

Expected behaviour? So why doesn't it throw this error from one folder, but does when run from another. Using the exact same command the only difference being the folder from which it is run, I either get an error or it runs perfectly. So from one folder it compiles, from the other it doesn't

cspotcode commented 2 years ago

Directory-sensitive behavior would be due to cwd-mode which is no longer the default as of v10.

https://github.com/TypeStrong/ts-node/releases/tag/v10.0.0