Error description
Usually, problems often occur in the target: 'node'
environment
There is a problem in the compiled file. Use require
as follows:
// for example 1:
const reload = require('require-reload')(requireFunc)
// for example 2:
function main () {
var data = require(dataPath)
}
An error will be reported when packing:
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
Critical dependency: the request of a dependency is an expression
Error resolution
Add the following code to the compiled file:
const requireFunc = typeof __webpack_require__=== 'function' ?__non_webpack_require__: require
(PS: the scheme was found in Du Niang, which is not original. Because the original text can not be found, you can record it yourself so that you can find it easily when you encounter a problem next time.)
Similar Posts:
- Causes and solutions of error reporting in require setting dynamic path
- Webpack high version pulls out CSS style and reports an error [Solved]
- [Solved] [email protected] Error: Cannot find module ‘webpack/bin/config-yargs‘
- Vue configures the compression-webpack-plugin to package and compress JS and CSS Error
- Webpack reports an error when using the cleanwebpackplugin plug-in
- Cannot findmodule’webpack-cli/bin/config-yargs
- TypeError: CleanWebpackPlugin is not a constructor
- How to Solve Critical dependency: the request of a dependency is an expression?
- How to solve the infinite loop of react. Useeffect()?
- Next (react) framework combined with lib-flexible, postcss-pxtorem do pc-side rem adaptation to solve the font-size is always 54px issue