简体   繁体   English

关键依赖:一个依赖的请求是一个表达式——react-universal-component

[英]Critical dependency: the request of a dependency is an expression -- react-universal-component

Warning:警告:

[HMR] bundle has 2 warnings
client.js:189 ./node_modules/babel-plugin-universal-import/universalImport.js 33:18-37
Critical dependency: the request of a dependency is an expression
 @ ./src/routes/index.js
 @ ./src/app-root.js
 @ multi babel-runtime/regenerator webpack-hot-middleware/client?reload=true ./src/app-root.js
./node_modules/react-universal-component/dist/utils.js 59:11-29
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/react-universal-component/dist/index.js
 @ ./src/routes/index.js
 @ ./src/app-root.js
 @ multi babel-runtime/regenerator webpack-hot-middleware/client?reload=true ./src/app-root.js

App-root.js应用程序-root.js

import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import Routes from './routes';

function render(Component) {
  ReactDOM.render(
    <AppContainer>
      <Component />
    </AppContainer>,
    document.getElementById('react-root')
  );
}

render(Routes);

if (module.hot) {
  module.hot.accept('./routes/index.js', () => {
    const NewRoutes = require('./routes/index.js').default;

    render(NewRoutes);
  });
}

src/routes/index.js源代码/路由/index.js

import React from 'react';
import { hot } from 'react-hot-loader';
import universal from 'react-universal-component';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import { Switch } from 'react-router';

const UniversalComponent = universal(({ page }) =>
  import(`../components/${page}`)
);

const Routes = () => (
  <Router>
    <div>
      <Link to="/">Home</Link>
      <Link to="/about">About Me</Link>

      <Switch>
        <Route exact path="/">
          <UniversalComponent page="counter" />
        </Route>

        <Route exact path="/about">
          <UniversalComponent page="about-me" />
        </Route>
      </Switch>
    </div>
  </Router>
);

export default hot(module)(Routes);

webpack.dev.js webpack.dev.js

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');

module.exports = {
  mode: 'development',
  devtool: 'source-map',

  entry: {
    // We want our client to reload in case a module doesn't recognise that it's parent changed
    vendor: ['react', 'react-dom'],
    main: [
      'babel-runtime/regenerator',
      'webpack-hot-middleware/client?reload=true',
      './src/app-root.js',
    ],
  },

  output: {
    filename: '[name].bundle.js',
    chunkFilename: '[name]-[hash:8].js',
    path: path.resolve(__dirname, '../dist'),
    publicPath: '/',
  },

  module: {
    rules: [
      {
        test: /\.js/,
        use: [
          {
            loader: 'babel-loader',
          },
        ],
        exclude: /node_modules/,
      },

      {
        test: /\.css/,
        use: [
          {
            loader: 'style-loader',
          },

          {
            loader: 'css-loader',
            options: {
              sourceMap: true,
              modules: true,
              localIdentName: '[name]--[local]--[hash:base64:8]',
            },
          },
        ],
      },

      {
        test: /\.scss/,
        use: [
          {
            loader: 'style-loader',
          },

          {
            loader: 'css-loader',
            options: {
              sourceMap: true,
              modules: true,
            },
          },

          {
            loader: 'sass-loader',
            options: {
              sourceMap: true,
            },
          },
        ],
      },

      {
        test: /\.html/,
        use: [
          {
            loader: 'html-loader',
            options: {
              attrs: ['img:src'],
            },
          },
        ],
      },

      {
        test: /\.(jpg|gif|png)/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: 'images/[name]-[hash:8].[ext]',
            },
          },
        ],
      },
    ],
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NamedModulesPlugin(),
    new HtmlWebpackPlugin({
      template: './src/index.html',
    }),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify('development'),
      },
    }),
    // new BundleAnalyzerPlugin({
    //   generateStatsFile: true,
    // }),
  ],

  optimization: {
    splitChunks: {
      chunks: 'all',
      cacheGroups: {
        vendor: {
          name: 'vendor',
          chunks: 'initial',
          minChunks: 2,
        },
      },
    },
  },

  devServer: {
    contentBase: 'dist',
    overlay: true,
    stats: {
      colors: true,
    },
    hot: true,
  },
};

Versions版本

"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-universal-import": "^3.0.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"express": "^4.16.3",
"express-static-gzip": "^0.3.2",
"nodemon": "^1.18.3",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-universal-component": "^3.0.0",
"webpack": "^4.16.2",
"webpack-cli": "^3.1.0",
"webpack-dev-middleware": "^3.1.3",
"webpack-hot-middleware": "^2.22.3"

I have no clue why am I seeing this warning when I am using react-universal-component.我不知道为什么在使用 react-universal-component 时会看到此警告。 I only see this when HMR is enabled and when I use react-universal-component.我只在启用 HMR 和使用 react-universal-component 时看到这一点。

我认为它是最新的 webpack@4.16.2,安装 webpack@4.16.0 它将在没有警告的情况下运行。

暂无
暂无

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

相关问题 关键依赖项:依赖项的请求是jQuery Form Validator插件上的一个表达式 - Critical dependency: the request of a dependency is an expression on jQuery Form Validator plugin Webpack编译不正确(严重依赖性:依赖性的请求是一个表达式) - Webpack not properly compiling (Critical dependency: the request of a dependency is an expression) 关键依赖:依赖的请求是使用延迟加载时的表达式 - Critical dependency: the request of a dependency is an expression while using lazy loading 关键依赖:依赖的请求是一个表达式(Angular CLI 警告) - Critical dependency: the request of a dependency is an expression (Angular CLI Warning) 如何解决我的npm包的“关键依赖关系:依赖关系的请求是一个表达式”错误? - How to resolve “Critical dependency: the request of a dependency is an expression” error for my npm package? ./node_modules/express/lib/view.js 中的 Webpack 警告关键依赖:依赖的请求是一个表达式 - Webpack WARNING in ./node_modules/express/lib/view.js Critical dependency: the request of a dependency is an expression 使用 react-pdf 时出现严重依赖警告 - Critical dependency warning when using react-pdf 关键依赖:将create-react-app从1.1.5更新到2.18 - Critical dependency: updating create-react-app from 1.1.5 to 2.18 FabricJs,Webpack无法编译-严重依赖 - FabricJs, Webpack not compiling - Critical dependency 警告-动态加载csv时严重依赖 - Warning - Critical Dependency when dynamically loading csv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM