简体   繁体   English

React找不到模块

[英]React couldn't find the module

I have structured everything properly. 我已经正确地构造了一切。 But while compiling react keep on says module not found how to fix? 但是在编译时继续说模块没找到怎么解决?

Module not found: Can't resolve 'ui-config/themes' in 'C:\\Users\\Goodwork\\desktop\\mihy-ui-framework\\src' 找不到模块:无法解析“ C:\\ Users \\ Goodwork \\ desktop \\ mihy-ui-framework \\ src”中的“ ui-config / themes”

this is my index file 这是我的索引文件

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from "react-router-dom";
import { MuiThemeProvider, createMuiTheme } from '@material- 
ui/core/styles';
import { Provider } from 'react-redux';
import store from 'ui-redux/store';
import './index.css';
import App from 'ui-views/App';
import registerServiceWorker from './registerServiceWorker';
import themeObject from "ui-config/themes";

Unless you have configured webpack with resolve alias ui-config , it's not going to work because webpack looks for npm module called ui-config in node_modules . 除非你已经配置了的WebPack resolve别名ui-config ,它不会工作,因为的WebPack查找名为NPM模块ui-confignode_modules

To fix it, Add to your webpack configuration the following: 要解决此问题,请在Webpack配置中添加以下内容:

resolve: {
    alias: {
         'ui-config: 'relative-path-to-ui-config'
    }
}

alternatively, you can adjust the relative path in your import 或者,您可以调整导入中的相对路径

import themeObject from "./ui-config/themes";

This is less optimal because eventually you'll end up struggeling with nested folders import '../../../../../' to find ui-config relative path. 这不是最佳选择,因为最终您将陷入嵌套文件夹导入'../../../../../'的困境,以查找ui-config相对路径。

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

相关问题 错误:模块构建失败:错误:找不到相对于目录“ / [project] frontend”的预设“ react-app” - Error: Module build failed: Error: Couldn't find preset “react-app” relative to directory “/[project] frontend” 错误:捆绑失败:错误:找不到相对于目录“ C:\\\\ Users \\\\…”的预设“ module:metro-react-native-babel-preset” - error: bundling failed: Error: Couldn't find preset “module:metro-react-native-babel-preset” relative to directory “C:\\Users\\…” React:找不到相对于目录“src”的预设“env react” - React: Couldn't find preset “env react” relative to directory “src” React 找不到模块 - React can't find Module 在“ npm”注册表中找不到软件包“ babel-present-react” - Couldn't find package “babel-present-react” on the “npm” registry 创建 package 时无法在“npm”注册表中找到 package“反应” - Couldn't find package "react" on the "npm" registry when creating a package 错误:找不到相对于目录的预设“ react-hmre” - Error: Couldn't find preset “react-hmre” relative to directory ESLint 错误 - ESLint 找不到配置“react-app” - ESLint error - ESLint couldn't find the config "react-app" 找不到发布的React组件模块 - can't find published React component module React找不到TypeScript声明模块 - React can't find TypeScript declarations module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM