我收到以下錯誤,嘗試從 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)
我也一直在終端上遇到這個錯誤我嘗試安裝插件
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>
)
}
需要一些解釋它意味著什么劑量以及為什么會發生這樣我才能解決它。
uj5u.com熱心網友回復:
您需要降級您的反應版本:在您的 package.json
"dependencies": {
...
"react": "16.14.0",
"react-dom": "16.14.0",
...
}
然后洗掉你的 node-modules 檔案夾并運行
yarn install or npm install
uj5u.com熱心網友回復:
安裝錯誤意味著您要安裝的庫取決于 React 16,而您的專案中安裝了 React 17
你可以使用這個命令 npm i gatsby-plugin-dark-mode --legacy-peer-deps
uj5u.com熱心網友回復:
你可以簡單地做:npm i gatsby-plugin-dark-mode --force
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/428354.html
上一篇:NPM安裝失敗,OSX
下一篇:yarnpkgadd--exactreactreact-domreact-scriptscra-template--cwd/Users/user/Desktop/app失敗
