Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 网页包:./src/index.tsx模块中的错误未找到:错误:Can';t解析'/App&x27;在'';_Reactjs_Webpack_Ts Loader_Tsx - Fatal编程技术网

Reactjs 网页包:./src/index.tsx模块中的错误未找到:错误:Can';t解析'/App&x27;在'';

Reactjs 网页包:./src/index.tsx模块中的错误未找到:错误:Can';t解析'/App&x27;在'';,reactjs,webpack,ts-loader,tsx,Reactjs,Webpack,Ts Loader,Tsx,尝试使用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://loca

尝试使用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
这是我的网页包配置文件:

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"
    })
  ]
};
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "sourceMap": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "noImplicitAny": true,
    "esModuleInterop": true
  }
}
这是我的tsconfig文件:

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"
    })
  ]
};
{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "sourceMap": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "strict": true,
    "noImplicitAny": true,
    "esModuleInterop": true
  }
}
这是我的index.tsx文件:

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

const root = document.querySelector('#root')
render(<App />, root)
import*as React from'React';
从'react dom'导入{render};
从“./App”导入应用程序;
const root=document.querySelector(“#root”)
渲染(,根)
感谢您的帮助
谢谢将以下内容添加到您的网页配置中:

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

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

更多信息请参见。

您的文件结构是什么样的?您确定您的应用程序文件与索引文件位于同一目录中吗?是的,它也位于src目录中。如果我在./src/components中设置应用程序组件,则会出现以下错误:
未找到./src/index.tsx模块中的错误:
错误:错误:无法解析。'C:\Users\user\Desktop\react resources样板文件\src'中的./components/App'@./src/index.tsx 15:28-55@multi(网页包)-开发服务器/客户端?http://localhost:8080 ./src/index.tsx