fastest-validator icon indicating copy to clipboard operation
fastest-validator copied to clipboard

Webpack - Critical dependency: the request of a dependency is an expression

Open michael-wolfenden opened this issue 5 years ago • 2 comments

Issue

When bundling with webpack and targeting node I get the following warnings:

WARNING in ./node_modules/fastest-validator/lib/helpers/prettier.js 10:13-26
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/fastest-validator/lib/validator.js
 @ ./node_modules/fastest-validator/index.js
 @ ./src/index.js

WARNING in ./node_modules/fastest-validator/lib/helpers/prettier.js 22:9-22
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/fastest-validator/lib/validator.js
 @ ./node_modules/fastest-validator/index.js
 @ ./src/index.js

Steps to reproduce

  1. Create a directory, initialize yarn, install webpack and webpack-cli
mkdir issue
cd issue
yarn init -y
yarn install webpack webpack-cli --dev
  1. Create src/index.js with the following contents:
const Validator = require("fastest-validator");
console.log(Validator)
  1. Execute webpack targeting node
npx webpack --target node
  1. You should see the following output
❯ npx webpack --target node
Hash: 48864f35cdc5c2a7af4a
Version: webpack 4.41.6
Time: 760ms
Built at: 02/14/2020 2:14:04 PM
  Asset      Size  Chunks             Chunk Names
main.js  24.9 KiB       0  [emitted]  main
Entrypoint main = main.js
[0] ./node_modules/fastest-validator/lib/helpers sync 160 bytes {0} [built]
[1] ./src/index.js 71 bytes {0} [built]
    + 23 hidden modules

WARNING in ./node_modules/fastest-validator/lib/helpers/prettier.js 10:13-26
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/fastest-validator/lib/validator.js
 @ ./node_modules/fastest-validator/index.js
 @ ./src/index.js

WARNING in ./node_modules/fastest-validator/lib/helpers/prettier.js 22:9-22
Critical dependency: the request of a dependency is an expression
 @ ./node_modules/fastest-validator/lib/validator.js
 @ ./node_modules/fastest-validator/index.js
 @ ./src/index.js

michael-wolfenden avatar Feb 14 '20 04:02 michael-wolfenden

any update on this issue? i got this warning too when using nextjs

mlazuardy avatar Mar 30 '23 15:03 mlazuardy

Any update ? It has been 4 months already. This is very annoying.

In the mean time - this is how to disabled it in nextjs:

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, { webpack }) => {
    // Added because of https://github.com/icebob/fastest-validator/issues/114
    // must be deleted after this issue is resolved
    config.plugins = config.plugins || [];
    const contextReplacementPlugin = new webpack.ContextReplacementPlugin(/\/fastest-validator\//, (data) => {
      for (const dependency of data.dependencies) {
        if (dependency.critical && dependency._parentModule.resource.includes('prettier.js')) {
          dependency.critical = undefined;
        }
      }

      return data;
    });

    config.plugins.push(contextReplacementPlugin);

    return config;
  },
};

module.exports = nextConfig;

mp3por avatar Sep 03 '23 08:09 mp3por