我正在尝试将Material-UI 样式安装到 React 项目,但每当我在终端中运行此命令时:
npm i @mui/styles
它读取以下消息:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: apollo-music-share@0.1.0
npm ERR! Found: react@18.1.0
npm ERR! node_modules/react
npm ERR! react@"^18.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from @mui/styles@5.8.0
npm ERR! node_modules/@mui/styles
npm ERR! @mui/styles@"*" from the root project
Run Code Online (Sandbox Code Playgroud)
这是 React 中的代码:
import { HeadsetTwoTone } from "@mui/icons-material";
import { AppBar, Toolbar, …Run Code Online (Sandbox Code Playgroud) 当我试图运行命令,我得到这个错误gulp watch-bs我UnderStrap儿童主题为WordPress。我已经使用该命令一年了,但是没有任何问题,但是今天当我将节点和npm更新为最新版本时,我收到了此错误。
ReferenceError: internalBinding is not defined
at internal/util/inspect.js:31:15
at req_ (C:\xampp\htdocs\node_modules\natives\index.js:137:5)
at require (C:\xampp\htdocs\node_modules\natives\index.js:110:12)
at util.js:25:21
at req_ (C:\xampp\htdocs\node_modules\natives\index.js:137:5)
at require (C:\xampp\htdocs\node_modules\natives\index.js:110:12)
at fs.js:42:21
at req_ (C:\xampp\htdocs\node_modules\natives\index.js:137:5)
at Object.req [as require] (C:\xampp\htdocs\node_modules\natives\index.js:54:10)
at Object.<anonymous> (C:\xampp\htdocs\node_modules\vinyl-fs\node_modules\graceful-fs\fs.js:1:99)
Run Code Online (Sandbox Code Playgroud)
我在这里读到,为了解决此问题,我需要运行以下命令:
npm install natives@1.1.6
但这无助于解决问题。
我还有其他东西吗?
我正在尝试将Typewriter Effect导入我的 NextJS 项目,但是每当我这样做时,我都会收到以下错误消息:
参考错误:窗口未定义
从我读到的内容来看,显示错误是因为它试图在服务器端而不是客户端加载库。
所以当我只是尝试像这样导入它时:
import Typewriter from 'typewriter-effect'
错误立即显示。
人们建议我尝试这样的事情:
let Typewriter
if (typeof window !== 'undefined') {
Typewriter = require( 'typewriter-effect' )
}
Run Code Online (Sandbox Code Playgroud)
然而,它也不是这样工作的。我收到一个错误,内容如下:
元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义。
我已经在很多地方搜索过这个问题的潜在解决方案,但我的尝试没有成功。
I really like the new React hooks and I'm using them frequently for a project I'm working on. I'm coming across a situation where I want to use the prevState in the useState hook, but I'm not really certain on how to do this.
I've tried something like this, but it fails to compile.
const [ someState, setSomeState ] = useState( new Map() )
setSomeState( prevState.someState.set( key, value ) )
Run Code Online (Sandbox Code Playgroud)
(by the way, this is to map an array of …
我正在尝试在 Heroku 上部署我的 nuxt 应用程序,但是每次我尝试部署它时,都会收到此错误消息,内容如下:
ERROR in ./node_modules/argon-design-system-free/assets/css/argon.min.css (./node_modules/css-loader/dist/cjs.js??ref--3-oneOf-1-1!./node_modules/postcss-loader/src??ref--3-oneOf-1-2!./node_modules/argon-design-system-free/assets/css/argon.min.css)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
Error: postcss-svgo: Error in parsing SVG: Unquoted attribute value
Line: 0
Column: 12
Char: \
at promises.push.getSvgo.optimize.then.catch.error (C:\Sites\unsplash-app\node_modules\postcss-svgo\dist\index.js:95:19)
@ ./node_modules/argon-design-system-free/assets/css/argon.min.css 4:14-147
@ ./.nuxt/App.js
@ ./.nuxt/index.js
@ ./.nuxt/client.js
@ multi ./.nuxt/client.js
Run Code Online (Sandbox Code Playgroud)
每次运行yarn build命令来构建我的项目时都会发生此错误。
在我的项目中,我决定使用名为Argon Design的免费设计系统,错误表明它的argon.min.css文件有问题,我不知道此时应该如何进行。
为了诊断问题,我尝试将xml-fix-loader模块安装到我的项目中,但它没有帮助解决我的问题。万一安装时是否应该执行其他步骤?
我正在尝试制作一个天气应用程序以学习一些 ReactJS。
我在组件内部的一个方法中使用此 fetch调用了OpenWeatherMap API 。componentDidMountWeatherCard
constructor() {
super()
this.state = {
weatherData: {}
}
}
componentDidMount() {
fetch('//api.openweathermap.org/data/2.5/weather?q=Calgary,ca&APPID=XXX')
.then(response => response.json())
.then(data => {
this.setState({
weatherData: data
})
})
}
Run Code Online (Sandbox Code Playgroud)
这是上述调用的示例 JSON 输出(给定有效的 API 密钥):
每当我想访问天气属性时,都会收到此错误消息:
类型错误:无法读取未定义的属性“0”
...我像这样访问它:
this.state.weatherData.weather[0].main
如果它有助于解决问题,这也是我的渲染方法:
render() {
return (
<div>
{this.state.weatherData.weather[0].main}
</div>
)
}
Run Code Online (Sandbox Code Playgroud)
有谁知道我遇到的问题可能是什么?非常感谢!
我在这里有这个代码:
const myMap = new Map()
myMap.set("banana", true)
myMap.set("apple", true)
Object.keys(myMap).forEach(key => {myMap.set(key, false)})
console.log(myMap.get("banana")) // returns true should return false
console.log(myMap.get("apple")) // returns true should return false
Run Code Online (Sandbox Code Playgroud)
我想将 this 的所有值都设置Map为false,但它根本不起作用。
我试过这样的事情:
Object.keys(myMap).forEach(key => myMap[key] = false)
Run Code Online (Sandbox Code Playgroud)
但这也不起作用。
有没有办法将 a 的所有键填充Map为特定值?