最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】ReactJS中引用react-month-picker的css出错:Module parse failed css Unexpected token

CSS crifan 4153浏览 0评论

折腾:

【已解决】给ReactJS的AdminLTE添加日期选择器

期间,用代码:

import MonthPicker from ‘react-month-picker’;
import ‘react-month-picker/css/month-picker.css’;

出错:

ERROR in ./node_modules/react-month-picker/css/month-picker.css
Module parse failed: /Users/crifan/dev/dev_root/daryun/Projects/xxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/react-month-picker/css/month-picker.css Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| .month-picker {
|   position: relative; }
|   .month-picker > .container {
@ ./src/App.js 53:0-50
@ ./src/index.js
@ multi (webpack)-dev-server/client?http://localhost:4000 webpack/hot/dev-server ./src/index.js
Child html-webpack-plugin for “index.html”:
                                   Asset      Size  Chunks             Chunk Names
    a465220e58a591b54728.hot-update.json  44 bytes          [emitted]
     + 1 hidden asset
       4 modules
webpack: Failed to compile.

先去试试另外的scss:

import ‘react-month-picker/scss/month-picker.scss’;

结果类似错误:

ERROR in ./node_modules/react-month-picker/scss/month-picker.scss
Module parse failed: /Users/crifan/dev/dev_root/daryun/Projects/xxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/react-month-picker/scss/month-picker.scss Unexpected character ‘@’ (5:0)
You may need an appropriate loader to handle this file type.
|
|
| @mixin text-ellipsis() {
|   text-overflow: ellipsis;
|   white-space: nowrap;
@ ./src/App.js 53:0-52
@ ./src/index.js
@ multi (webpack)-dev-server/client?http://localhost:4000 webpack/hot/dev-server ./src/index.js
Child html-webpack-plugin for “index.html”:
                                   Asset      Size  Chunks             Chunk Names
    07c102fb52fd98b59695.hot-update.json  44 bytes          [emitted]
     + 1 hidden asset
       4 modules
webpack: Failed to compile.

去看了看源码:

https://github.com/nickeljew/react-month-picker/blob/master/css/month-picker.css

感觉是:

此处的css,实际上是less

所以改名为:

import ‘react-month-picker/css/month-picker.less’;

结果就可以编译通过了:

【总结】

此处react-month-picker的month-picker.css实际上的语法是less,所以解析出错,改为:

month-picker.less

就可以正常解析了。

转载请注明:在路上 » 【已解决】ReactJS中引用react-month-picker的css出错:Module parse failed css Unexpected token

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.166 seconds, using 22.19MB memory