【问题标题】:Cannot find module "react-slick"找不到模块“react-slick”
【发布时间】:2017-06-17 12:05:47
【问题描述】:

我正在尝试在我的 React 项目中使用 react-slick。 当我尝试导入它时

import Slider from 'react-slick';

我收到这个错误

Cannot find module "react-slick"

还有其他人有这个问题吗?

https://github.com/akiran/react-slick 安装

npm install react-slick

同时为 css 和字体安装 slick-carousel

npm install slick-carousel

React V "react@^15.4.1"

NPM 安装结果

npm install react-slick --save
(node:14297) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
fb-lite@1.1.0 ..blal
└─┬ react-slick@0.14.5 
  ├─┬ json2mq@0.2.0 
  │ └── string-convert@0.2.1 
  ├─┬ react-responsive-mixin@0.4.0 
  │ ├── can-use-dom@0.1.0 
  │ └── enquire.js@2.1.1 
  └─┬ slick-carousel@1.6.0 
    └── jquery@3.1.1 


npm install slick-carousel --save
(node:14298) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
fb-lite@1.1.0 ..blal
└── slick-carousel@1.6.0 

【问题讨论】:

  • 没有足够的上下文来帮助您解决这个问题。你能显示npm install react-slickpackage.json前后的输出吗?
  • 刚刚在上面的帖子中添加了 npm install 结果
  • 很好,看起来很正常——package.json 是什么样的?您能否也发布您要导入麻烦库的文件?
  • 如果你使用var Slider = require('react-slick');而不是import会发生什么?
  • 当我像上面那样使用 require 时也是如此。我要导入的文件只是一个普通的 js 文件,其他导入也很好。当我再次注释掉 react-slick 导入时,如果一切正常。

标签: reactjs react-slick


【解决方案1】:

在你的 react 组件文件中: 从'react-slick'导入滑块;

在 package.json 检查版本: “反应光滑”:“^0.15.4”

这对我有用。

【讨论】:

    【解决方案2】:

    我也遇到过同样的问题。 请运行以下命令:-

    yarn remove react-slick // If you installed through yarn
    
     or
    
    npm uninstall react-slick // If you installed through npm
    
    then run:-
    
    npm install react-slick --save
    

    【讨论】:

      【解决方案3】:

      再次卸载并安装react-slick。 如果这不起作用,请检查 package.json 文件中的模块:

      "dependencies": {
      "react-router-dom": "^5.2.0",
      "react-scripts": "^4.0.3",
      "react-slick": "^0.28.1",
      "react-twitter-embed": "^3.0.3",
      "reactjs-popup": "^2.0.5",
      "slick-carousel": "^1.8.1"   }
      

      【讨论】:

        猜你喜欢
        • 2022-06-12
        • 2021-12-25
        • 2015-09-20
        • 2020-05-10
        • 2019-09-06
        • 2018-09-06
        • 1970-01-01
        • 2023-01-09
        相关资源
        最近更新 更多