Skip to content

TypeScript

Most times if you are using TypeScript, no configuration is required. Quokka uses ts-node with swc to run your TypeScript files.

Overriding Quokka’s TypeScript Dependencies

Quokka is installed with four dependencies that are required to execute TypeScript files:

  • TypeScript (used to compile your TypeScript files)
  • ts-node (used to import other TypeScript files from your project)
  • swc (used to compile your TypeScript imports)
  • tsconfig-paths (used for TypeScript’s module resolution)

Depending on your project and the version of Quokka that you are using, you may want to use a different version of these dependencies. You may override the version for any (or all) of these by installing the dependency either as a project dependency or in your global quokka ~/.quokka/node_modules folder. Quokka will attempt to find each dependency first in the project folder, then in the global ~/.quokka/node_modules folder; if the dependency is not found in the project or global folder, Quokka will use its own version.

Please note: When using Quokka’s embedded version of ts-node, ts-node will be started in “fast” mode using process.env.TS_NODE_TRANSPILE_ONLY = true. You may override this behavior by installing ts-node in your project or global folder.

Compiler version

Unless the path to the desired TypeScript version is specified in the Quokka settings

{
"ts": {
"path": "...typescript"
}
}

Quokka.js will try to use TypeScript from the following places (in priority order):

  1. local project’s node_modules,
  2. global config folder’s node_modules,
  3. editor’s embedded TypeScript version (if any),
  4. Quokka.js embedded TypeScript version, if nothing was found up to this point.

Compiler settings

If you need to override some compiler options from the project’s tsconfig.json, or if you don’t have a tsconfig.json file, but need to specify some settings:

{
"ts": {
"compilerOptions": {
"target": "es6",
...
}
}
}

Using SWC for dependency compilation

Quokka uses ts-node with swc to compile TypeScript dependencies because it is significantly faster than using the TypeScript compiler. If for some reason, you do not want to use swc to compile your Quokka file dependencies, you may do so by specifying the "swc": false settings in your Quokka configuration:

{
"ts": {
"swc": false
...
}
}