0

我正在使用 react-window ^1.8.6 版本(在我的依赖项下)。当我尝试使用纱线构建我的项目时,出现以下错误。

./node_modules/react-window/dist/index.esm.js 中的错误模块未找到:错误:无法解析 '/Users/xxxxxx/Workspace/xxxxx/ 中的 '@babel/runtime/helpers/esm/assertThisInitialized'组件库/node_modules/react-window/dist' @ ./node_modules/react-window/dist/index.esm.js 3:0-86 160:60-82 160:83-105 164:18-40 164: 41-63 1066:60-82 1066:83-105 1070:18-40 1070:41-63 @ ./src/components/PDFViewer/Viewer.tsx @ ./src/components/PDFViewer/PDFViewer.tsx @ ./ src/components/PDFViewer/index.ts @ ./src/components/DocumentViewer/DocumentViewer.tsx @ ./src/components/DocumentViewer/index.ts @ ./src/index.ts

全套如下 完整的错误集

纱线版本 1.22.17

npm 版本 8.1.2

节点版本 v16.13.2

webpack 版本 ^4.44.1

我的 Webpack 配置看起来像

const path = require('path');
const webpack = require('webpack');

module.exports = {
    entry: './src/index.ts',
    mode: 'production',
    output: {
        path: path.resolve(__dirname, 'lib'),
        filename: 'the-component-library.js',
        libraryTarget: 'umd',
        globalObject: 'this',
        library: 'theComponentLibrary',
    },
    module: {
        rules: [
            {
                test: /\.(ts|tsx)$/,
                exclude: /(node_modules|bower_components)/,
                use: ['ts-loader'],
            },
            {
                test: /\.(scss|css)$/,
                use: ['style-loader', 'css-loader', 'sass-loader'],
            },
            {
                test: /\.svg$/,
                use: ['@svgr/webpack'],
            },
            {
                test: /\.(gif)$/i,
                use: [
                    {
                        loader: 'file-loader',
                    },
                ],
            },
        ],
    },
    externals: [
        {
            react: 'react',
        },
        '@material-ui/core',
        '@material-ui/lab',
        /@material-ui\/core\/*./,
        /@material-ui\/lab\/*./,
        'react-simple-gestures',
        'react-dropzone',
    ],
    resolve: {
        extensions: ['.ts', '.tsx'],
    },
    plugins: [
        // Ignore all locale files of day.js
        new webpack.IgnorePlugin(/^\.\/locale$/),
    ],
};

我该如何解决这个问题?

4

1 回答 1

0

哦,我可以通过更改 Webpack 配置来解决问题,如下所示

差异

于 2022-02-10T03:40:23.160 回答