TypeScript "stopped working" locally

Hello everyone,

The TypeScript Track has been updated to Yarn 4 with PnP enabled. In short this is a method to deduplicate content on your harddisk/ssd/storage instead of the singularity that is called node_modules. In other words: it saves time and space, perhaps even spacetime?

However, because PnP installed packages are no longer available in the exercise directory, and tools (such as typescript / tsc) and editors (such as vscode) rely on the packages to be available locally, you must take a few new steps.

The installation instructions and testing instructions have been updated to reflect this.

  1. We now use corepack instead of bundling a version of yarn locally. Run corepack enable yarn on Node LTS or newer to receive a “last known good” version of of yarn. Before you do that you want to delete yarn installed via other methods such as npm install -g yarn.
  2. We rely on the @yarnpkg/sdks to provide the resolver to read packages from the PnP cache. This means that you need to run the SDK hook-up once per assignment (and potentially restart your editor) for PnP to work.

Example commands for vscode

# Download an exercise
exercism download [...]
cd [...]

# This replaces yarn install
corepack enable yarn
corepack yarn install
corepack yarn dlx @yarnpkg/sdks vscode

# Open the editor
code .

If there are questions or issues, feel free to respond here. The TypeScript Test Runner has also been updated and should be able to handle both the older Yarn 3 and the newly updated Yarn 4 solutions.

5 Likes

I can’t run tests locally for typescript track exercises. Tried first in emacs on debian and later with webstorm on osx with arm, both are not working. I used corepack yarn install and corepack yarn dlx @yarnpkg/sdks base, before trying corepack yarn test

this is what I’m getting

corepack yarn test

node:internal/modules/run_main:115
    triggerUncaughtException(
    ^
Error: Qualified path resolution failed: we looked for the following paths, but none could be accessed.

Source path: /Users/redjocker/Exercism/typescript/two-fer/.meta/test-runner.mjs
Not found: /Users/redjocker/Exercism/typescript/two-fer/.meta/test-runner.mjs

    at makeError (/Users/redjocker/Exercism/typescript/two-fer/.pnp.cjs:14434:34)
    at resolveUnqualified (/Users/redjocker/Exercism/typescript/two-fer/.pnp.cjs:16176:13)
    at resolveRequest (/Users/redjocker/Exercism/typescript/two-fer/.pnp.cjs:16216:14)
    at Object.resolveRequest (/Users/redjocker/Exercism/typescript/two-fer/.pnp.cjs:16272:26)
    at resolve$1 (file:///Users/redjocker/Exercism/typescript/two-fer/.pnp.loader.mjs:2045:21)
    at nextResolve (node:internal/modules/esm/hooks:791:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:238:30)
    at MessagePort.handleMessage (node:internal/modules/esm/worker:255:24)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:816:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)

Node.js v22.2.0

It seems that test-runner.mjs is missing inside the .meta directory. I don’t know why that happens, but it is possible that I misconfigured something. For now you can solve it by manually copying the following and save it as test-runner.mjs inside .meta. Sorry about this!

cc @ErikSchierboom / @iHiD is this a thing where it (now) only downloads files from .meta if they are inside the files array? Or is this a thing that is only broken for existing solutions? Then why did it update package.json?

hi was able to run now, but I had to change some things. So the file is on “root level”, so I have /two-fer/test-runner.mjs

then I had problems with config.json since what we have is tsconfig.json, so I changed on file line 9 to ./tsconfig.json.

then I had problems on tsconfig.json, some parse error on comments with //. So I removed all comments on tsconfig.json.

Now tests are running and failing like they should because I have not solved it yet.

actually I just tried to replicate on emacs and it was not working if test-runner.mjs was not in two-fer/.meta/ for some unknown reason.

so I had to change line 9 to ../tsconfig.json instead and have two-fer/.meta/test-runner.mjs

and this worked also on webstorm

The reason the file needs to be inside the .meta directory is because the script in package.json in the root refers to .meta/test-runner.mjs.
It is supposed to read config.json from the .meta directory, so do not change that to tsconfig.json or ../tsconfig.json.

If you do not see config.json inside the .meta directory, please let me know because then I know what to solve.

redjocker@debian:~/playground/exercism/typescript/resistor-color-duo$ exercism download --track=typescript --exercise=resistor-color-trio

Downloaded to
/home/redjocker/playground/exercism/typescript/resistor-color-trio
redjocker@debian:~/playground/exercism/typescript/resistor-color-duo$ cd /home/redjocker/playground/exercism/typescript/resistor-color-trio
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ tree -a
.
├── babel.config.cjs
├── eslint.config.mjs
├── .exercism
│   ├── config.json
│   └── metadata.json
├── HELP.md
├── jest.config.cjs
├── package.json
├── README.md
├── resistor-color-trio.test.ts
├── resistor-color-trio.ts
├── tsconfig.json
├── .vscode
│   ├── extensions.json
│   └── settings.json
├── yarn.lock
└── .yarnrc.yml

3 directories, 15 files
1 Like

Got it. It’s in .exercism.

I’ll make a change to the exercise. For now can you put test-runner.mjs in that folder and change package.json to say .exercism?

I think that will resolve your issues

ok, let me try, but this happened on all exercises so far. I started on hello-world and did one by one in order, all with same file structure

1 Like
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ cd ..
redjocker@debian:~/playground/exercism/typescript$ rm -r ./resistor-color-trio/ 
redjocker@debian:~/playground/exercism/typescript$ exercism download --track=typescript --exercise=resistor-color-trio

Downloaded to
/home/redjocker/playground/exercism/typescript/resistor-color-trio
redjocker@debian:~/playground/exercism/typescript$ cd /home/redjocker/playground/exercism/typescript/resistor-color-trio
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ cp ../resistor-color-duo/.meta/test-runner.mjs ./.exercism/
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ cp ../resistor-color-duo/config.sh ./
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ cat ./config.sh
#!/usr/bin/bash

corepack yarn install
corepack yarn dlx @yarnpkg/sdks base
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ bash ./config.sh
➤ YN0000: · Yarn 4.3.1
➤ YN0000: ┌ Resolution step
(...)
➤ YN0000: └ Completed
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ sed -i 's/\.\.\/tsconfig\.json/\.\/config\.json/g' .exercism/test-runner.mjs
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ sed -i 's/\.meta/\.exercism/g' ./package.json 
redjocker@debian:~/playground/exercism/typescript/resistor-color-trio$ corepack yarn test
[tests] tsc: ✅, tstyche: ❌, jest: ✅, 
[tests] tsc (compile)

ok it worked

1 Like

Thank you for testing. I will now make the change to the track so it will be fixed for everyone once they update there exercises.

The underlying issue here is that I forgot that the .meta folder is renamed to .exercism for students.

1 Like

Once Move test-runner.mjs to exercise root and add commentary by SleeplessByte · Pull Request #1525 · exercism/typescript · GitHub is merged, you should be able to update your existing exercises and then you no longer need to apply the workaround, unless I made a boo-boo again.

hi thx for all the support.

I’m glad I was able to be helpful and help fix track issues.

More important than not making mistakes is how you deal with mistakes when that happen and you certainly did a good support job here.

3 Likes

Today Aug 7th '24, I have been unable to run the robot-simulator tests locally and I think I may have found an issue within the file test-runner.mjs.

On line 39 we assign a value to configDirectory based on the existence of the .meta or .exercism directory.

const configDirectory = existsSync(metaDirectory)
  ? metaDirectory
  : execSync(exercismDirectory)
    ? exercismDirectory
    : null

I changed the line execSync(exercismDirectory) to existsSync(exercismDirectory) and was able to run the tests.

Hopefully this helps and I just want to give a heartfelt thank you to all the maintainers of the Exercism tracks.

2 Likes

Thanks for reporting. A PR with fix is up. Fix call to existsSync by SleeplessByte · Pull Request #1528 · exercism/typescript · GitHub

This was merged. The changes should be live on the site shortly. You must update the exercise and download again to see the changes.

cc @MrXcitement @RedJocker

1 Like