TypeScript错误 – 无法找到模块’stytch’或其对应的类型声明.ts(2307) 标签

huangapple go评论52阅读模式
英文:

TypeScript Error - Cannot find module 'stytch' or its corresponding type declarations.ts(2307) tags

问题

以下是您要翻译的内容:

"I'm working on a Next.js application and trying to import the 'stytch' module in TypeScript. However, I'm running into an issue where TypeScript is unable to find the module or its type declarations. The error message is:

Cannot find module 'stytch' or its corresponding type declarations.ts(2307)

Here's the TypeScript code where the error is occurring:

import * as stytch from 'stytch';

let client;

const loadStytch = () => {
  if (!client) {
    client = new stytch.Client({
      project_id: process.env.STYTCH_PROJECT_ID || "",
      secret: process.env.STYTCH_SECRET || "",
      env:
        process.env.STYTCH_PROJECT_ENV === "live"
          ? stytch.envs.live
          : stytch.envs.test,
    });
  }

  return client;
};

export default loadStytch;

This code is located in a file called loadStytch.tsx.

I have the 'stytch' module installed in my project and it is at version "^5.18.1", as confirmed by running npm list stytch.

The 'stytch' module has a type declaration file at node_modules\stytch types\lib\client.d.ts.

/// <reference types="node" />
import * as http from "http";
import { CryptoWallets } from "./crypto_wallets";
import { MagicLinks } from "./magic_links";
import { OAuth } from "./oauth";
import { OTPs } from "./otps";
import { Passwords } from "./passwords";
import { Sessions } from "./sessions";
import { TOTPs } from "./totps";
import { Users } from "./users";
import { WebAuthn } from "./webauthn";
interface Config {
    project_id: string;
    secret: string;
    env: string;
    timeout?: number;
    agent?: http.Agent;
}
export declare class Client {
    users: Users;
    magicLinks: MagicLinks;
    otps: OTPs;
    oauth: OAuth;
    passwords: Passwords;
    sessions: Sessions;
    totps: TOTPs;
    webauthn: WebAuthn;
    cryptoWallets: CryptoWallets;
    private fetchConfig;
    constructor(config: Config);
}
export {};

Despite all of this, I'm still getting the error. I've tried running npm install to make sure all dependencies are installed, but the error persists.

found 0 vulnerabilities

I would appreciate any help in resolving this issue. Thank you in advance for your time and assistance."

英文:

I'm working on a Next.js application and trying to import the 'stytch' module in TypeScript. However, I'm running into an issue where TypeScript is unable to find the module or its type declarations. The error message is:

Cannot find module &#39;stytch&#39; or its corresponding type declarations.ts(2307)

Here's the TypeScript code where the error is occurring:

import * as stytch from &#39;stytch&#39;;

let client;

const loadStytch = () =&gt; {
  if (!client) {
    client = new stytch.Client({
      project_id: process.env.STYTCH_PROJECT_ID || &quot;&quot;,
      secret: process.env.STYTCH_SECRET || &quot;&quot;,
      env:
        process.env.STYTCH_PROJECT_ENV === &quot;live&quot;
          ? stytch.envs.live
          : stytch.envs.test,
    });
  }

  return client;
};

export default loadStytch;

This code is located in a file called loadStytch.tsx.

I have the 'stytch' module installed in my project and it is at version "^5.18.1", as confirmed by running npm list stytch.

The 'stytch' module has a type declaration file at node_modules\stytch ypes\lib\client.d.ts.

/// &lt;reference types=&quot;node&quot; /&gt;
import * as http from &quot;http&quot;;
import { CryptoWallets } from &quot;./crypto_wallets&quot;;
import { MagicLinks } from &quot;./magic_links&quot;;
import { OAuth } from &quot;./oauth&quot;;
import { OTPs } from &quot;./otps&quot;;
import { Passwords } from &quot;./passwords&quot;;
import { Sessions } from &quot;./sessions&quot;;
import { TOTPs } from &quot;./totps&quot;;
import { Users } from &quot;./users&quot;;
import { WebAuthn } from &quot;./webauthn&quot;;
interface Config {
    project_id: string;
    secret: string;
    env: string;
    timeout?: number;
    agent?: http.Agent;
}
export declare class Client {
    users: Users;
    magicLinks: MagicLinks;
    otps: OTPs;
    oauth: OAuth;
    passwords: Passwords;
    sessions: Sessions;
    totps: TOTPs;
    webauthn: WebAuthn;
    cryptoWallets: CryptoWallets;
    private fetchConfig;
    constructor(config: Config);
}
export {};

Despite all of this, I'm still getting the error. I've tried running npm install to make sure all dependencies are installed, but the error persists.

found 0 vulnerabilities

I would appreciate any help in resolving this issue. Thank you in advance for your time and assistance.

答案1

得分: 2

用以下内容替换这一行:

const stytch = require("stytch");
英文:

Replace this line

import * as stytch from &#39;stytch&#39;;

with const stytch = require(&quot;stytch&quot;);

huangapple
  • 本文由 发表于 2023年7月17日 19:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76703998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定