fastest-validator
fastest-validator copied to clipboard
Webpack - Critical dependency: the request of a dependency is an expression
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
- Create a directory, initialize yarn, install webpack and webpack-cli
mkdir issue
cd issue
yarn init -y
yarn install webpack webpack-cli --dev
- Create
src/index.js
with the following contents:
const Validator = require("fastest-validator");
console.log(Validator)
- Execute
webpack
targetingnode
npx webpack --target node
- 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
any update on this issue? i got this warning too when using nextjs
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;