简体   繁体   English

如何解决 React Webpack 应用程序中的“Module not found: Error: Can't resolve ... multi @babel/polyfill ./react/index.js”

[英]How to solve 'Module not found: Error: Can't resolve … multi @babel/polyfill ./react/index.js' in React Webpack Application

We have a React application with webpack and we have an error in our Bitbucket Pipeline when we build the application.我们有一个带有 webpack 的 React 应用程序,当我们构建应用程序时,我们的 Bitbucket Pipeline 中出现错误。

We launch the npm run build command int the CI inside a Debian docker container and we have this error:我们在 Debian docker 容器内的 CI 中启动npm run build命令,但出现以下错误:

[INFO] ERROR in ./react/classes/searchparams/parametrosGeneralesForm.js
[INFO] Module not found: Error: Can't resolve '../../dataTables/dataTablesId' in '/opt/atlassian/pipelines/agent/build/bapplication/bapplication-web/src/main/resources/static/resources/react/classes/searchparams'
[INFO]  @ ./react/classes/searchparams/parametrosGeneralesForm.js 9:15-55
[INFO]  @ ./react/datatables/configurations/configuracion/parametrosGenerales.js
[INFO]  @ ./react/datatables/utils/getParameters.js
[INFO]  @ ./react/datatables/dataTable.jsx
[INFO]  @ ./react/content/body/mainContentBody.jsx
[INFO]  @ ./react/content/content.jsx
[INFO]  @ ./react/contentWrapper/ContentWrapper.jsx
[INFO]  @ ./react/index.js
[INFO]  @ multi @babel/polyfill ./react/index.js

We have this error and similars import errors with multiple files.我们有这个错误,并且有多个文件的类似导入错误。

Our .babelrc file is:我们的 .babelrc 文件是:

{
    "presets":["@babel/env", "@babel/react"],"plugins": ["@babel/plugin-proposal-class-properties","@babel/transform-async-to-generator","@babel/syntax-dynamic-import"]
}

We have the webpack configuration in two files webpack.base.config.js and webpack.dev.config.js .我们在两个文件webpack.base.config.jswebpack.dev.config.js有 webpack 配置。

Our webpack.base.config.js is:我们的webpack.base.config.js是:

const path = require('path');
const webpack = require("webpack");
const APP_DIR = path.resolve(__dirname, './react');
const PropertiesReader = require('properties-reader');
const Eslanguaje = PropertiesReader('../../languages/bapplication_es.properties')._properties;
const Enlanguaje = PropertiesReader('../../languages/bapplication_en.properties')._properties;
const Defaultlanguaje = PropertiesReader('../../languages/bapplication.properties')._properties;
const ROUTING_PROPS = PropertiesReader('../../routing.properties')._properties;
const CONSTANTS_PROPS = PropertiesReader('../../constants.properties')._properties;
const RemoteProperties = PropertiesReader('../../application-develop.properties')._properties;
const LocalProperties = PropertiesReader('../../application-local.properties')._properties;
const ProductionProperties = PropertiesReader('../../application-production.properties')._properties;
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');

let properties="";
switch (process.env.NODE_ENV){
    case "local":
        properties = LocalProperties;
        break;
    case "development":
        properties = RemoteProperties;
        break;
    case "production":
        properties = ProductionProperties;
        break;
}
const springPath = properties["server.servlet.context-path"];
const CONTEXT =(springPath!==undefined&&springPath!==null)?springPath:"";
module.exports =  {
    entry: {
        app: ['@babel/polyfill', APP_DIR + '/index.js']
    },
    resolve: {
      extensions: ['.js', '.jsx']
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                use: ["babel-loader", "eslint-loader"],
                exclude: /node_modules/
            },
            {   test: /\.jsx$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                use: [ 'style-loader', 'css-loader' ]
            }
        ]
    },
    output: {
        path:  path.join(__dirname, './dist'),
        filename: 'bundle.js',
        publicPath: CONTEXT+'/res/dist/',
    },
    externals: {
        'esLanguaje': JSON.stringify(Eslanguaje),
        'enLanguaje': JSON.stringify(Enlanguaje),
        'defaultLanguaje': JSON.stringify(Defaultlanguaje),
        'ROUTING_PROPS': JSON.stringify(ROUTING_PROPS),
        'CONSTANTS_PROPS': JSON.stringify(CONSTANTS_PROPS),
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
            'process.env.DEBUG': JSON.stringify(true),
            'process.env.API_URL': JSON.stringify(CONTEXT)
        }),
        new HardSourceWebpackPlugin()
    ]
};

Our webpack.dev.config.js is:我们的webpack.dev.config.js是:

const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.config');

module.exports = merge(baseConfig, {
    devtool: 'inline-source-map',
    mode: "development"
});

The parametrosGeneralesForm.js file have the correct require to the file path: parametrosGeneralesForm.js文件对文件路径有正确的要求:

const IDTABLES = require('../../dataTables/dataTablesId');

The file that import is dataTablesId.js .导入的文件是dataTablesId.js

The folder structure is:文件夹结构为:

react
|_dataTables
|   |_dataTablesId.js
|
|_classes
    |_searchparams
       |_parametrosGeneralesForm.js

Is it possible that our webpack.base.config.js have errors with the resolver code?我们的webpack.base.config.js是否有可能在解析器代码中出现错误?

暂无
暂无

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

相关问题 如何修复“./src/index.js Module not found: Can&#39;t resolve &#39;loadash” in my react app? - How to fix "./src/index.js Module not found: Can't resolve 'loadash" in my react app? &#39;react&#39; - 运行 npm start 后,它给出 ./src/index.js Module not found: Can&#39;t resolve &#39;react&#39; in &#39;C:\\Users\\...\\src&#39; 错误 - 'react' - After run npm start it gives ./src/index.js Module not found: Can't resolve 'react' in 'C:\Users\...\src' error Babel 错误:找不到模块:无法解析'<local_structure> /node_modules/react-scripts/node_modules/babel-loader/lib/index.js' 在新组件之后</local_structure> - Babel error: Module not found: Can't resolve '<local_structure>/node_modules/react-scripts/node_modules/babel-loader/lib/index.js' after new component ./src/index.js 未找到模块:无法解析“aws-amplify”React - ./src/index.js Module not found: Can't resolve 'aws-amplify' React 未能编译./src/index.js找不到模块:无法在 - Failed to compile ./src/index.js Module not found: Can't resolve 'react' in 用酶和玩笑测试 React 给出错误无法从“index.js”中找到模块“@babel/polyfill/lib/noConflict” - Testing React with enzyme and jest giving error Cannot find module '@babel/polyfill/lib/noConflict' from 'index.js' 如何解决 React 错误模块构建失败(来自 ./node_modules/babel-loader/lib/index.js): - how to resolve React error Module build failed (from ./node_modules/babel-loader/lib/index.js): 找不到模块:无法在反应应用程序中解析&#39;/root/project/node_modules/eslint-loader/index.js - Module not found: Can't resolve '/root/project/node_modules/eslint-loader/index.js in react app ReactJS:将 index.js 转换为 index.tsx - 未找到模块:错误:无法解析“./App” - ReactJS: Converting index.js to index.tsx - Module not found: Error: Can't resolve './App' 找不到模块:错误:无法解析“core-js/fn/array”React Webpack - Module not found: Error: Can't resolve 'core-js/fn/array' React Webpack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM