我正在沿着一门课程,讲师没有出现这个错误,而我的代码与他的代码相同。我在/utils文件夹中有一个实用程序函数,该文件夹与正在导入../utils/makeId的index.js位于同一文件夹中。我正在使用eslint,两个文件都是.js文件,但没有导入。
import { useState, useEffect, useRef } from 'react';
import { Banner, CreatorCard } from '../components';
import images from '../assets';
import { makeId } from '../utils/makeId';
const Home = () => {
const parentRef = useRef(null);
const scrollRef = useRef(null);
return (
<div className="flex justify-center sm:px-4 p-12">
<div className="w-full minmd:w-4/5">
<Banner
name="Discover, collect, and sell extraordinary NFTs"
childStyles="md:text-4xl sm:text-2xl xs=text-xl text-left"
parentStyles="justify-start mb-6 h-72 sm:h-60 p-12 xs:p-4 xs:h-44 rounded-3xl"
/>
<div>
<h1 className="font-poppins dark:text-white text-nft-black-1 text-2xl minlg:text-4xl font-semibold ml-4 xs:ml-0">Best Creators</h1>
<div
className="relative flex-1 max-w-full flex mt-3"
ref={parentRef}
>
<div
className="flex flex-row w-max overflow-x-scroll no-scrollbar select-none"
ref={scrollRef}
>
{[6, 7, 8, 9, 10].map((i) => (
<CreatorCard
key={`creator-${i}`}
rank={i}
creatorImage={images[`creator${i}`]}
creatorName={`0x${makeId(3)}...${makeId(4)}}`}
/>
))}
</div>
</div>
</div>
</div>
</div>
);
};
export default Home;
makeId.js
export const makeId = (length) => {
let result = '';
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for (let i = 0; i < length; i += 1) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
};
Screenshot
我试着在我的eslintrc.js中添加扩展设置,我在一个类似的帖子中找到了它;虽然这修复了我的导入错误,但我仍然会在网站上得到编译错误。
1条答案
按热度按时间u2nhd7ah1#
问题是它需要是'./utils/makeId'而不是'../utils/makeId',我不知道为什么,但我猜是因为/utils和index.js在同一个文件夹中,所以正确的语法是./而不是../。