我的目录结构是:
|
|__src
| |_components
| |
| |_A
| |_index.tsx
|
|
tsconfig.json
package.json
Run Code Online (Sandbox Code Playgroud)
我想这样导入A:
从 'src/components/A' 导入 { A };
我的 tsconfig.json 看起来像这样:
{
"compilerOptions": {
"baseUrl": "",
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"jsx": "react",
"lib": ["es5", "es2015", "es2016", "dom"],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"outDir": "dist",
"removeComments": false,
"skipLibCheck": true,
"strict": true,
"strictFunctionTypes": false,
"strictNullChecks": false,
"suppressImplicitAnyIndexErrors": true,
"target": "es5",
"typeRoots": ["./node_modules/@types"],
"types": ["node", "jest"],
"paths": {
"*": ["./node_modules/@types/*", …Run Code Online (Sandbox Code Playgroud) 我正在vitest与一个NextJS13应用程序集成,但在简单的测试运行中遇到了问题。
不确定问题是什么,我尝试进行一些调整,但vitest.config.ts没有成功。我尝试添加该dir选项,修改该include选项以从源文件中获取文件,但没有成功。
我以为可能与文件有关tsconfig.json,但它仍然输出错误。
这是文件的目录
以下是有问题的文件:
vitest.config.ts
/// <reference types="vitest" />
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: 'setupTests.ts',
// dir: './src'
// includeSource: ['src/**/*.{js,ts,tsx}'],
},
});
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"lib": ["es6", "dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true, …Run Code Online (Sandbox Code Playgroud)