1

I have a TypeScript project, based on Node.js, with several modules (using workspaces). Everything executes correctly, but I’m still receiving warnings. In particular, when running this (as a package.json ‘script’ in Yarn)

ts-node --project path/tsconfig.json path/script.ts <args-to-script>

I’m seeing two classes of warnings:

  • In Visual Studio Code, squiggly underlines in the imports of makefont.ts, because I (have to) specify .ts file extensions;
  • At the command-prompt, warning messages on execution, stating that “ExperimentalWarning: Type Stripping is an experimental feature and might change at any time”

I think the two warnings are related. I’m using NodeJS 23.7.0, Yarn 1.22.22, ts-node 10.9.2, TypeScript 5.5.4

Imports with file extensions:

"import { glyphs } from 'fonts/font1.ts' // squiggly underline!"

Without the .ts, I get “Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/andrew/projects/retrofabulationzx/app/node_modules/fonts/font1' imported from /Users/andrew/projects/retrofabulationzx/app/rom/build/makefont.ts

Note that, additionally, I’ve had to split off a type import (Glyph) into a separate import statement. I suspect that both of these issues are related to the ‘Type Stripping’ mentioned below:

ExperimentalWarning

It seems that ts-node is using the (experimental) Node Type Stripping feature to run TypeScript… I am sure that it wasn’t doing this previously, before I implemented workspaces…

Does ts-node have problems running within a Yarn/NPM ‘workspace’?

What the project looks like:

  • fonts/ (workspace)
    • font1.ts
    • package.json
    • tsconfig.json
  • rom/ (workspace)
    • build/
      • makefont.ts
      • tsconfig.json
    • generated/ (output directory)
    • package.json
  • package.json
  • tsconfig.json

/package.json

{
    "private": true,
    "workspaces": [
        "fonts",
        "rom",
    ],
    "devDependencies": {
        "@jest/globals": "^29.1.2",
        "@types/node": "^22.4.0",
        "ts-jest": "^29.1.2",
        "ts-node": "^10.9.2",
        "typescript": "^5.5.4"
    },
    "packageManager": "[email protected]"
}

/tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "module": "ES6",
        "outDir": "dist",
        "esModuleInterop": true,
        "moduleResolution": "node"
    },
    "include": [],
    "exclude": [ "**/node_modules" ],
}

fonts/package.json

{
    "name": "fonts",
    "version": "1.0.0",
    "type": "module"
}

fonts/tsconfig.json

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "composite": true
    },
    "include": [ "./*.ts" ]
}

rom/package.json

{
    "name": "rom",
    "version": "1.0.0",
    "type": "module",
    "devDependencies": {
        "@types/node": "^22.4.0",
        "fonts": "1.0.0",
        "ts-node": "^10.9.2",
        "typescript": "^5.5.4",
        "zxsys": "1.0.0"
    },
    "scripts": {
        "genfont": "ts-node --project build/tsconfig.json build/makefont.ts generated/font.z80",
        // plus others
    }
}

rom/build/tsconfig.json

{
    "extends": "../../tsconfig.json",
    "ts-node": {
        "esm": true
    },
    "compilerOptions": {
    },
    "references": [
        { "path": "../../fonts" },
        // +others
    ],
    "include": [ "./*.ts" ],
}

Exact command-line invocation

yarn workspace rom genfont
3
  • 1
    " I can provide " - you need to, this is specific to your case. You don't have to specify extensions if ts is properly configured. What is "fonts"? A package from the workspace? You need to structure it in a way this allows imports from inside the package. "Type Stripping" is node feature, not ts-node, this means that ts files weren't processed by ts Commented Feb 5 at 11:20
  • @EstusFlask, Thanks, (I didn’t want to clutter up the question with too much stuff!) Have added all the relevant file contents, I think. That was my thought: that the file was not being processed by the TS compiler, but it’s definitely being invoked via ts-node. Commented Feb 6 at 9:08
  • 1
    Since ts-node calls node inside, this warning is what happens when node executes .ts directly, also notice that ts-node is abandoned and can add another layer of its own problems. In my experience this structure of ts-only monorepo projects results in troubles. Try to alias "fonts" in "rom" with compilerOptions-paths config (not references-path as you did), e.g. see "@foo/shared/*": ["../foo-shared/src/*"] entry here stackoverflow.com/questions/75403735 , this way it's expected that you could import it like "fonts/font1" Commented Feb 7 at 12:40

1 Answer 1

0

The reason seems to be the use of ES Modules. By the look of things, when ESM are used, ts-node simply falls back to calling node, which is why you get these warnings. Disabling esm in the ts-node config and changing the type to commonjs in my "package.json" files helped in my case.

However, this isn't ideal. A quick Google search suggests that ES Modules are the future. At the same time, after taking a quick look at ts-node's code, it seems to be deliberately skipping type checks for ES Modules (https://github.com/TypeStrong/ts-node/blob/main/esm/transpile-only.mjs). So, you either get ES Modules, or type checking - but not both. I'm new to TypeScript and node.js, and would really appreciate a better solution.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes… My eventual ‘solution’ was switching from Node to Deno :) It works really smoothly and made my TypeScript problems go away!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.