所以我正在制作一个精巧的打字稿库,文件夹结构如下
|- dist/
|- src/
|- components/
|- index.ts
|- tests/
|- src/
|- components/
|- index.ts
|- package.json
|- tsconfig.json
|- rollup.config.js
|- package.json
|- tsconfig.json
|- rollup.config.js
在tests
文件夹中,我有一个单独的苗条打字稿项目来测试该库,并且我试图将文件从tests
文件夹之外直接导入到tests
项目中,我这个错误
[!] 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";
我已经尝试了几种方法,例如在tests
项目tsconfig.json
中使用路径并添加rootDirs
,仍然不能解决问题,有人知道如何解决此问题吗?谢谢您的帮助
这是主项目的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
}
}
这是tests
项目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/*"]
}
}
}