【问题标题】:ReferenceError: window is not defined import cssReferenceError: 窗口未定义导入 css
【发布时间】:2019-10-13 13:20:31
【问题描述】:

试图在 react js applciation 中导入 css 但它抛出错误

这是一个仪表板应用程序,其中节点 js 在服务器端并在客户端做出反应 js

webpack.base.js

  module.exports = {
    //Running babel to every file
    module: {
        rules: [
            {
                test: /\.js?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                options: {
                    presets: [
                        'react',
                        'stage-0',
                        ['env', { targets: { browsers: ['last 2 versions'] } }]
                    ]
                }
            }, {
                test: /\.css$/,
                loader: "style-loader!css-loader"
            }, {
                test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
                loader: 'url-loader?limit=100000'
            }

        ]
    }//end module
}

style.css

.segment {
    border-top:14px solid #14a767;
    border-bottom: 3px solid #14a767;
    margin: 2px 2px 2px 140px;
    width: 80%
 }

Home.js(组件)

import '../../css/style.css'
        return window && document && document.all && !window.atob;
        ^

ReferenceError: 窗口未定义

【问题讨论】:

  • 你想达到什么目的?该错误与您的CSS无关,它与您的JS代码有关...
  • 你把return window && document && document.all && !window.atob;放在组件里面的什么地方
  • @Tenusha :: ``` 返回窗口 && 文档 && document.all && !window.atob; ```这是错误
  • 如果你在这样的函数中使用它,f1 = function(){ return window && document && document.all && !window.atob }。会执行成功,返回HTMLAllCollection对象。
  • 现在可以正常工作了 :-) 谢谢@Tenusha..

标签: css reactjs webpack less


【解决方案1】:

实际问题是我使用了语义 UI 反应节点模块,并且每个组件都有自己的样式。所以就是这样,它不允许我创建具有类样式的 CSS,.,。所以我使用了 ID 而不是类风格,而且它的工作很酷。,

我的确切问题是这个 ::: custom className semantic ui react

【讨论】:

    猜你喜欢
    • 2016-10-16
    • 2021-03-30
    • 2020-10-08
    • 2018-05-27
    • 2020-09-18
    • 2020-11-12
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多