wallabyjs / quokka

Repository for Quokka.js questions and issues
https://quokkajs.com
1.18k stars 31 forks source link

Importing files from project in new Quokka typescript file #942

Closed fdx-kunal closed 8 months ago

fdx-kunal commented 8 months ago

Issue description or question

When creating a new typescript file how can I import files from the project directory without using an absolute path.

Sample code

import { ISomeInterface } from "./ISomeInterface.ts";
Cannot find module './ISomeInterface.ts' or its corresponding type declarations.ts(2307)

Quokka.js Console Output

​​​​​Quokka PRO 'Untitled-2.ts' (node: v20.11.1, TypeScript: v4.7.4)

Code editor version

Visual Studio Code v1.87.2?

OS name and version

Windows

smcenlly commented 8 months ago

You don't need to specify an absolute path, but Quokka does run from your project root for unsaved files. This means that the file name will need to be relative to the project working directory.

For example, if your interface is in:

<rootDir>/src/ISomeInterface.ts

Then your import for an unsaved file will need to be:

import { ISomeInterface } from "./src/ISomeInterface.ts";

If you're not already familiar with tsconfig.json paths setting, you may find that a more useful way to reference your imports. With the paths setting, you will be able to consistently import your imports from all files (vs. relative paths). Please note that this may have a downstream impact on your build / bundling tools, so you will need to evaluate if this works for your specific project.