找不到模块“react-slick”。

4

我正在尝试在我的React项目中使用react-slick。

当我尝试导入它时

import Slider from 'react-slick';

我遇到了这个错误。
Cannot find module "react-slick"

有其他人遇到这个问题吗? https://github.com/akiran/react-slick 安装
npm install react-slick

同时安装slick-carousel用于CSS和字体

npm install slick-carousel

React 版本号为 "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 的输出结果吗?包括更改前后的内容。 - Taylor Jones
刚刚在上面的帖子中添加了npm安装结果。 - me-me
太好了,看起来正常——package.json是什么样子的?你能否也把你正在导入有问题的库的文件发布出来? - Taylor Jones
有其他人能够让它工作吗? - me-me
是的,我可以使用它,你必须声明 var Slider = require('react-slick') 而不是使用 import。我使用的是这个库的版本 => "react-slick": "^0.14.6",确保你没有使用太旧的版本或错误的库。 - awzx
显示剩余2条评论
6个回答

4
在你的 React 组件文件中: import Slider from 'react-slick';
在 package.json 中检查版本: "react-slick": "^0.15.4"
这对我有用。

3

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

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

1

这对我很有帮助

rm -rf node_modules

delete package-lock.json

npm i

0

当我将代码从这个

import Slider from "react-slick";

改为这个

import Slider from 'react-slick';

时,它对我起作用了。


0

这对我来说很好用

npm uninstall react-slick --legacy-peer-deps 

-1

卸载并重新安装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"   }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接