简体   繁体   English

JavaScript on Next.js 和 React 导入错误“无法解析模块'../utils/makeId'.eslintimport/no-unresolved 的路径”

[英]JavaScript on Next.js and React import error "Unable to resolve path to module '../utils/makeId'.eslintimport/no-unresolved"

I'm following along a course and the instructor doesn't have this error while my code is identical to his.我正在学习一门课程,当我的代码与他的代码相同时,讲师没有出现此错误。 I've got a utility function in the /utils folder which is in the same folder as the index.js that is importing../utils/makeId.我在 /utils 文件夹中有一个实用程序 function,它与正在导入的 index.js 位于同一文件夹中../utils/makeId。 I'm using eslint and everything both files are.js files but it's not importing.我正在使用 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 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截屏

I tried adding extension settings in my eslintrc.js I found on a similar post;我尝试在类似帖子中找到的 eslintrc.js 中添加扩展设置; while that fixed my import error I would still get a compile error on the website.虽然这修复了我的导入错误,但我仍然会在网站上遇到编译错误。

The problem was it needed to be './utils/makeId' instead of '../utils/makeId', I'm not sure why but I guess because /utils is in the same folder as index.js the proper syntax is./ not../.问题是它需要是 './utils/makeId' 而不是 '../utils/makeId',我不确定为什么,但我猜是因为 /utils 与 index.js 在同一个文件夹中,正确的语法是。/ 不是../。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 eslint 中解析模块路径(导入/未解析) - Unable to resolve path to module (import/no-unresolved) in eslint 带有 Eslint 的 Vite.js 上的 Vue 3 — 无法解析模块 eslint 的路径(导入/未解决) - Vue 3 on Vite.js with Eslint — Unable to resolve path to module eslint(import/no-unresolved) 错误无法解析模块“html-webpack-plugin”导入的路径/未解决 - error Unable to resolve path to module 'html-webpack-plugin' import/no-unresolved 与 TS 反应,eslint 错误导入/未解决 - React with TS, eslint error import/no-unresolved 如何在 ESLint 中为导入文件解析“import/no-unresolved”! 对于 javascript 和 nodejs - How to resolve "import/no-unresolved" in ESLint for import files! for javascript and nodejs 规则 &#39;import/no-unresolved&#39; 的生成的故事条目.js 错误 - generated-stories-entry.js error for rule 'import/no-unresolved' 如何在Webpack 4中使用eslint的安装来解决导入/无法解决的问题 - how to resolve import/no-unresolved with setup of eslint in webpack 4 在 Next.js 中导入 react-hook-mousetrap 时出现“无法在模块外使用导入语句”错误 - "Cannot use import statement outside a module" error when importing react-hook-mousetrap in Next.js javascript import/require 错误:无法从“…/src/static/js/react_apps/utils”中找到模块“@react-select/monorepo” - javascript import/require Error: Cannot find module '@react-select/monorepo' from '…/src/static/js/react_apps/utils' eslint 在声明文件上抛出 import/no-unresolved 错误 - eslint throwing import/no-unresolved error on declaration files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM