简体   繁体   English

Webpack:./src/index.tsx中的错误找不到模块:错误:无法在“…”中解析“ ./App”

[英]Webpack: ERROR in ./src/index.tsx Module not found: Error: Can't resolve './App' in '…'

I have the following error when trying to serve my app using webpack-dev-server: 尝试使用webpack-dev-server服务我的应用程序时出现以下错误:

ERROR in ./src/index.tsx
Module not found: Error: Can't resolve './App' in 
'C:\Users\user\Desktop\react-resources-boilerplate\src'
 @ ./src/index.tsx 15:28-44
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.tsx

Here is my webpack config file: 这是我的webpack配置文件:

const HtmlWebPackPlugin = require('html-webpack-plugin');
const path = require('path');

module.exports = {
  entry: path.resolve(__dirname, 'src', 'index.tsx'),
  module: {
    rules: [
      {
        test: /\.ts|\.tsx$/,
        loader: "ts-loader",
      },
    ]
  },

  plugins: [
    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html"
    })
  ]
};

Here is my tsconfig file: 这是我的tsconfig文件:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "sourceMap": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "noImplicitAny": true,
    "esModuleInterop": true
  }
}

Here is my index.tsx file: 这是我的index.tsx文件:

import * as React from 'react';
import { render } from 'react-dom';
import App from './App';

const root = document.querySelector('#root')
render(<App />, root)

Help appreciated Thanks 帮助赞赏谢谢

Add the following to your webpack config: 将以下内容添加到您的webpack配置中:

module.exports = {
    // ...
    // existing code goes here
    // ...

    resolve: {
        extensions: ['.ts', '.tsx'],
    },
};

More info in the docs . 文档中有更多信息。

暂无
暂无

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

相关问题 ReactJS:将 index.js 转换为 index.tsx - 未找到模块:错误:无法解析“./App” - ReactJS: Converting index.js to index.tsx - Module not found: Error: Can't resolve './App' [React Webpack]:找不到模块:错误:无法解析 'C:\Users\...' 中的 'src/views/UserList' - [React Webpack]: Module not found: Error: Can't resolve 'src/views/UserList' in 'C:\Users\…' 找不到输入模块中的错误:错误:无法解析“ ./src” - ERROR in Entry module not found: Error: Can't resolve './src' in webpack错误-找不到模块:错误:无法解析“ ImageFile” - webpack error - Module not found: Error: Can't resolve 'ImageFile' 未找到 ./src/App.jsx 模块中的错误:错误:无法解析“./component/Footer” - ERROR in ./src/App.jsx Module not found: Error: Can't resolve './component/Footer' 找不到入口模块:错误:无法解析'./src/index.js' - Entry module not found: Error: Can't resolve './src/index.js' 找不到模块:错误:无法解析“/home/user/Desktop/my_app/src”中的“./app” - Module not found: Error: Can't resolve './app' in '/home/user/Desktop/my_app/src' 将应用程序部署到 Netlify:找不到模块:错误:无法解析 '/opt/build/repo/src' 中的 './pages/HomePage' - React app deployment to Netlify : Module not found: Error: Can't resolve './pages/HomePage' in '/opt/build/repo/src' 找不到输入模块:错误:无法解析“ ./src” - Entry module not found: Error: Can't resolve './src' Webpack:找不到模块:错误:无法解析“./containers” - Webpack: Module not found: Error: Can't resolve './containers'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM