Open AnkurAgrawal opened 3 months ago
The plan to solve the bug involves creating type declaration files for the missing modules and updating the tsconfig.json
file to include these new type declarations. This will inform TypeScript about the types used in these modules, allowing it to pass the type checking phase without errors.
The bug is caused by the absence of type declarations for the modules 'vue-auth3/drivers/auth/bearer-token'
and 'vue-auth3/drivers/http/fetch'
. TypeScript cannot find these modules or their corresponding type declarations, resulting in the TS2307
error during type checking. This issue does not affect the build process or the runtime behavior of the application, which is why the build completes successfully and the app runs fine in both dev and production modes.
Create the following type declaration files to resolve the missing module errors:
src/types/vue-auth3/drivers/http/fetch.d.ts
declare module 'vue-auth3/drivers/http/fetch' {
// Example type declarations
export interface FetchOptions {
method: string;
headers?: Record<string, string>;
body?: string;
}
export function fetch(url: string, options?: FetchOptions): Promise<Response>;
}
src/types/vue-auth3/drivers/auth/bearer-token.d.ts
declare module 'vue-auth3/drivers/auth/bearer-token' {
// Example type declarations
export interface BearerTokenOptions {
token: string;
refreshToken?: string;
}
export default function driverAuthBearerToken(options: BearerTokenOptions): void;
}
tsconfig.json
Modify the tsconfig.json
file to include the new type declaration files:
{
"compilerOptions": {
"target": "ESNEXT",
"module": "ESNext",
"declaration": true,
"strict": true,
"declarationDir": "types",
"moduleResolution": "node",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": false
},
"include": ["src", "src/types/**/*.d.ts"],
"exclude": ["node_modules", "test"]
}
pnpm install
.pnpm build
. Notice that the build succeeds.pnpm type-check
.Observe the errors:
src/main.ts:9:35 - error TS2307: Cannot find module 'vue-auth3/drivers/auth/bearer-token' or its corresponding type declarations.
9 import driverAuthBearerToken from 'vue-auth3/drivers/auth/bearer-token'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.ts:10:29 - error TS2307: Cannot find module 'vue-auth3/drivers/http/fetch' or its corresponding type declarations.
10 import driverHttpAxios from 'vue-auth3/drivers/http/fetch'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ticket title: error TS2307: Cannot find module
error in vue3 + vite while type checking (vue-tsc --build
)
Ticket Description:
I am getting the following error while type checking a vue3 + vite project. The configs are default as generated by pnpm create vue@latest
. Even though type checking via vue-tsc
results in an error the build complete successfully. Also the app runs fine in both dev and production mode.
src/main.ts:9:35 - error TS2307: Cannot find module 'vue-auth3/drivers/auth/bearer-token' or its corresponding type declarations.
9 import driverAuthBearerToken from 'vue-auth3/drivers/auth/bearer-token'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.ts:10:29 - error TS2307: Cannot find module 'vue-auth3/drivers/http/fetch' or its corresponding type declarations.
10 import driverHttpAxios from 'vue-auth3/drivers/http/fetch'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Repro Steps:
pnpm install
.pnpm build
. Notice that the build succeed.pnpm type-check
.Expected: No error in type checking Observed: Type checking fails with error.
Is there something missing from the config?
Click here to create a Pull Request with the proposed solution
Files used for this task:
I believe this problem is due to your tsconfig
configuration. I downloaded your code and used default tsconfig
without any problems
I have same problem, the problem is in tsconfig moduleResolution, the package is not support "bundler" and must set "Node10", but tsconfig's docs says "bundler" is best chooise over "Node10" (node).
Summary
I am getting the following error while type checking a vue3 + vite project. The configs are default as generated by
pnpm create vue@latest
. Even though type checking viavue-tsc
results in an error the build complete successfully. Also the app runs fine in both dev and production mode.Repro Steps:
pnpm install
.pnpm build
. Notice that the build succeed.pnpm type-check
.Expected: No error in type checking Observed: Type checking fails with error.
Is there something missing from the config?