3

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/*"]
        }
    }
}
KawishBit
  • 650
  • 1
  • 8
  • 18
  • 1
    This sounds like an issue with your build setup. Could you post your `package.json` and bundle config (`rollup.config.js`) ? – dummdidumm Sep 17 '20 at 07:43
  • @dummdidumm thanks for taking your time to reply, fortunately i have found another stackoverflow question that tackled this issue, and i think this is the solution that i was looking for : https://stackoverflow.com/questions/47729344/how-to-share-code-between-typescript-projects – KawishBit Sep 28 '20 at 04:12

0 Answers0