【问题标题】:css-loader will not import css into node anymore, throwing errorcss-loader 将不再将 css 导入节点,抛出错误
【发布时间】:2017-07-22 05:02:58
【问题描述】:

最初,我有一个 index.html 页面,其中包含一个包含 <div id="react-content"></div 元素的 div。我现在将把手作为模板语言包含在内,以服务于渲染为字符串的反应 ui 元素。

问题是,我正在使用 css-loader 将 css 导入我的节点项目,但它不再导入。当我使用 index.html 文件时,它可以工作,但现在不行,节点抛出错误(不是 webpack)。我宁愿不将样式表作为<link /> 包含在公共目录中。我想不出为什么会发生这种情况的原因。

错误

SyntaxError: /Users/***/Documents/Isomorphic React-Node/
Restuarant /src/components/homePageStyle.css: Unexpected token (6:0)

    import React, {Component}  from 'react';
    import PropTypes from 'prop-types';
    import HeaderMenu from './HeaderMenu';
    import MainVisualDisplay from './MainVisualDisplay';
    import homePageStyle from './homePageStyle.css';

    //HomePage component
     const HomePage = () => 
    {  
    return (

    <div>
        <HeaderMenu item1="Menu" item2="Locations" item3="About Us"/>
    </div>
    )     
}
//
const forHeaderMenu = () => (
    HomePage.item1: PropTypes.string.isRequired,
    HomePage.item2: PropTypes.string.isRequired,
    HomePage.item3: PropTypes.string.isRequired
)

const forMainVisualDisplay = () =>
(
    HomePage.displayImages: PropTypes.array
)

HomePage.propTypes = {
        forHeaderMenu,
        forMainVisualDisplay
    };

export default HomePage;

【问题讨论】:

  • 我猜你的服务器正在为你的源代码而不是 webpack 生成的代码提供服务。

标签: node.js reactjs webpack loader css-loader


【解决方案1】:

想通了。当 Node 只知道 .js 时,它试图编译 .css 扩展名。我需要延期。

require.extensions['.css'] = () => {
  return;
};

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多