gpt4 book ai didi

node.js - 找不到模块 'gatsby-plugin-dark-mode' 的声明文件

转载 作者:行者123 更新时间:2023-12-05 03:28:53 28 4
gpt4 key购买 nike

我收到以下错误,试图从 gatsby-plugin-dark-mode 导入 ThemeToggler

module "C:/Users/Karim Elnemr/Desktop/my-gatsby-website/node_modules/gatsby-plugin-dark-mode/index"
Could not find a declaration file for module 'gatsby-plugin-dark-mode'. 'C:/Users/Karim Elnemr/Desktop/my-gatsby-website/node_modules/gatsby-plugin-dark-mode/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/gatsby-plugin-dark-mode` if it exists or add a new declaration (.d.ts) file containing `declare module 'gatsby-plugin-dark-mode';`ts(7016)

而且我在尝试安装 blugin 时在终端上也遇到了这个错误

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: gatsby-starter-hello-world@0.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR! react@"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"16.x" from gatsby-plugin-dark-mode@1.1.2
npm ERR! node_modules/gatsby-plugin-dark-mode
npm ERR! gatsby-plugin-dark-mode@"^1.1.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!

下面是我导入上述插件的地方

import React from "react"
import { ThemeToggler } from "gatsby-plugin-dark-mode"

export default function ThemeToggle() {
return (
<ThemeToggler>
{({ theme, toggleTheme }) => {
if (theme == null) {
return null
}
return (
<label className="theme-switch">
<input
type="checkbox"
onChange={e => toggleTheme(e.target.checked ? "dark" : "light")}
checked={theme === "dark"}
/>
<span className="toggle"></span>
</label>
)
}}
</ThemeToggler>
)
}

需要一些解释这是什么意思以及为什么会发生这样我才能解决它。

最佳答案

安装错误意味着您要安装的库依赖于 React 16,而您的项目中安装了 React 17

你可以使用这个命令npm i gatsby-plugin-dark-mode --legacy-peer-deps

关于node.js - 找不到模块 'gatsby-plugin-dark-mode' 的声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71154643/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com