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

Compile time errors being suppressed when using esm #2129

Open
Stono opened this issue Jul 29, 2024 · 0 comments
Open

Compile time errors being suppressed when using esm #2129

Stono opened this issue Jul 29, 2024 · 0 comments

Comments

@Stono
Copy link

Stono commented Jul 29, 2024

I really struggled to think of the correct title for this, so please edit it as required. I went down a rabbithole today whilst moving one of our apps to esm, as it was failing to start (with ts-node) due to the following node error:

❯ node --experimental-specifier-resolution=node --loader ts-node/esm lib/index.ts
node:internal/modules/run_main:115
    triggerUncaughtException(
    ^
[Object: null prototype] {
  [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
}

Node.js v22.5.1

Doesn't really give away much. It turned out however that the root caused we missed a return type on a promise eg Promise needed to be Promise<void>. This error was visible if you did a tsc, but ts-node was giving this output.

After gradually chipping away at the code to make a minimal example; i managed to reproduce it with a really simple bit of code that doesn't even technically have an error in it.

Assuming your code is in ./lib, create ./lib/index.ts:

import { SomeServer } from './server.js'

const webServer = new SomeServer()

and ./lib/server.ts:

export class SomeServer {}

If you try and start this; you'll get the error. The only thing "wrong" with this code is the fact that webServer is an unused variable. If i add console.log(webServer), eg:

import { SomeServer } from './server.js'

const webServer = new SomeServer()
console.log(webServer)

Then all is well:

❯ node --experimental-specifier-resolution=node --loader ts-node/esm lib/index.ts

SomeServer {}

Specifications

  • versions:
❯ ./node_modules/.bin/ts-node -vv
ts-node v10.9.2
node v22.5.1
compiler v5.3.3
  • tsconfig.json:
{
  "compilerOptions": {
    "lib": ["ES2022", "DOM"],
    "module": "ES2022",
    "target": "ES2022",
    "rootDir": "./",
    "outDir": "./built",
    "baseUrl": "./",
    "allowJs": false,
    "checkJs": false,
    "alwaysStrict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noEmitOnError": false,
    "sourceMap": false,
    "declaration": false,
    "strictBindCallApply": true,
    "noImplicitOverride": true,
    "noUncheckedIndexedAccess": true,
    "incremental": false,
    "skipDefaultLibCheck": true,
    "experimentalDecorators": true,
    "noUnusedLocals": true,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["lib/**/*.ts", "test/**/*.ts"],
  "exclude": ["node_modules/**/*"]
}
  • Operating system and version: Mac
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

No branches or pull requests

1 participant