Webpack 4 - 打字稿入口文件

Webpack 4 - typescript entry file

我正在设置我的小型个人项目,偶然发现了打字稿和反应的问题。当我使用 index.js 作为入口点时,一切正常,但是当我使用 .tsx 文件时,出现以下错误:

EntryModuleNotFoundError: Entry module not found: Error: Can't resolve './src'

我本可以放弃并使用 .js,但我很好奇为什么会这样。详细的错误消息指定它只查找 .wasm、.mjs、.js 和 .json 文件扩展名,忽略我放入 resolve 的任何内容:{ extensions: [] }.

no extension
  Field 'browser' doesn't contain a valid alias configuration
  [path_to_project]\src\index doesn't exist
.wasm
  Field 'browser' doesn't contain a valid alias configuration
  [path_to_project]\src\index.wasm doesn't exist
.mjs
  Field 'browser' doesn't contain a valid alias configuration
  [path_to_project]\src\index.mjs doesn't exist
.js
  Field 'browser' doesn't contain a valid alias configuration
  [path_to_project]\src\index.js doesn't exist
.json
  Field 'browser' doesn't contain a valid alias configuration
  [path_to_project]\src\index.json doesn't exist

我的 webpack.config.js 文件:

const path = require('path');

module.export = {
    mode: 'development',
    devtool: 'cheap-module-source-map',
    entry: {
        app: './src/index.tsx'
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'pfgen.bundle.js'
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                exclude: /node_modules/
            }
        ]
    },
    resolve: {
        extensions: ['.ts', '.d.ts', '.tsx']
    }
};

这是我的项目库:REPOSITORY 这是我使用的 webpack 版本:

"ts-loader": "^5.3.1",
"typescript": "^3.2.2",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"

将 module.export 更改为模块。导出。刚刚使用您的 Git 存储库在我这边成功地拉取、更改和构建。

顺便说一句,还要将 /node_modules 添加到您的 .gitignore 中,这样像 VSCode 这样的编辑器在与 master.

进行比较时就不会查看该目录

干杯!