使用next.js和typescript导入节点模块失败

lrl1mhuk  于 5个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(52)

我正在尝试使用一个软件包,brypt,我已经使用npm install bcrypt安装在项目中。
我可以在node_modules文件夹中看到包,但当试图在我的代码中导入时,我收到错误:“* 无法找到模块'bcryptjs'或其相应的类型声明 *”。
我已经尝试修改tsj.json中的moduleResolution值,因为我认为这可能是我的问题,但仍然是一个问题。有人能看到/指导我,我在这里做错了什么吗?
这是我的tslog.json文件的内容:

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": [
        "./*"
      ]
    }
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

字符串
这就是我尝试使用方法的地方:

import { IUserAuthenticatedResponse } from "@/types/userAccountTypes";
import axios from "axios";
import bcrypt from 'bcryptjs';

export const dynamic = 'force-dynamic' // defaults to auto
export async function POST(request: Request) {
    const body = await request.json();
    const { emailAddress, password } = body;

    async function authenticateUser(cancel = false): Promise<IUserAuthenticatedResponse[]> {
        const salt = bcrypt.genSaltSync(10)
        const response = await api.request({
            url: process.env.apiBaseUrl + 'authenticateUserAccount/' + emailAddress + "/" + password,
            method: "GET",
            // retrieving the signal value by using the property name
            signal: cancel ? cancelApiObject[this.get.name].handleRequestCancellation().signal : undefined,
        })
        return response.data
    }
}


谢谢你能提供的任何帮助。

0ve6wy6x

0ve6wy6x1#

不知道为什么,但似乎我不得不使用以下安装:

npm i --save-dev @types/bcrypt

字符串

相关问题