How to import typescript file from outside of the project folder

Viewed 773

So I'm making a svelte typescript library and the folder structure is as follows

|- dist/
|- src/
  |- components/
  |- index.ts
|- tests/ 
  |- src/
  |- components/
  |- index.ts
  |- package.json
  |- tsconfig.json
  |- rollup.config.js
|- package.json
|- tsconfig.json
|- rollup.config.js

in tests folder I have a separate svelte typescript project to test the library and I'm trying to import the files from outside the tests folder directly to tests project, it gave me this error

[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
..\src\utilities\navbarStore.ts (1:12)
1: import type { NavThemes } from "src/interfaces";
               ^
2: import { writable } from "svelte/store";

I've tried several stuff like using paths in tests project tsconfig.json and adding rootDirs, still doesn't fix the problem, anyone knows how to tackle this issue? thanks for your help

here's the main project's tsconfig.json :

{
    "include": ["src/**/*"],
    "exclude": ["node_modules/*", "public/*", "tests/*", "docs/*", "demo/*"],
    "compilerOptions": {
        "baseUrl": ".",
        "lib": ["es2017", "dom"],
        "target": "es2017",
        "module": "esnext",
        "sourceMap": true,
        "rootDir": ".",
        "composite": true,
        "noEmitOnError": true,
        "noErrorTruncation": true,
        "declaration": true,
        "declarationMap": true,
        "noEmit": false,
        "strict": true,
        "noImplicitThis": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "types": ["svelte", "node"],
        "allowSyntheticDefaultImports": true,
        "importsNotUsedAsValues": "error",
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "esModuleInterop": true
    }
}

here's tests project tsconfig.json :

{
    "include": ["src/**/*", "../src/**/*"],
    "exclude": ["node_modules/*", "__sapper__/*", "public/*"],
    "compilerOptions": {
        "lib": ["es2017", "dom"],
        "target": "es2017",
        "noEmitOnError": true,
        "noErrorTruncation": true,
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "types": ["svelte", "node"],
        "forceConsistentCasingInFileNames": true,
        "noImplicitThis": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "rootDirs": [".", "../"],
        "baseUrl": ".",
        "paths": {
            "svelteprojectts/*": ["../src/*"],
            "svelteprojectjs/*": ["../dist/es/*"]
        }
    }
}
0 Answers
Related