question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack reports "the request of a dependency is an expression" (SSR, Server-Side only)

See original GitHub issue

πŸ› Bug Report

Webpack v4 reports the following issue when executed:

WARNING in ./node_modules/@loadable/server/lib/util.js 26:9-28
    Critical dependency: the request of a dependency is an expression

The code involved in loadable looks like this:

var smartRequire = function smartRequire(modulePath) {
  if (process.env.NODE_ENV !== 'production') {
    clearModuleCache(modulePath);
  } // Use __non_webpack_require__ to prevent Webpack from compiling it
  // when the server-side code is compiled with Webpack
  // eslint-disable-next-line camelcase


  if (typeof __non_webpack_require__ !== 'undefined') {
    // eslint-disable-next-line no-undef
    return __non_webpack_require__(modulePath);
  } // eslint-disable-next-line global-require, import/no-dynamic-require


  return require(modulePath);
};

The error seems to happen in the last line.

We do not have any dynamic imports in the whole application. All of our code is using simple strings right now.

Interestingly, beside the critical warning we cannot see any negative side effect. The application seems to work correctly.

I tried to figure out where this __non_webpack_require__ is coming from. Seems like it is a convention introduced by Webpack. Maybe there is some error in the combination of Babel/Webpack plugins we use.

Earlier in our development this error was not there. It seems it was introduced by some updates to the dependencies. Right now we have the following versions installed:

yarn list --depth 0 --pattern loadable
yarn list v1.13.0
β”œβ”€ @loadable/babel-plugin@5.6.0
β”œβ”€ @loadable/component@5.6.0
β”œβ”€ @loadable/server@5.6.0
└─ @loadable/webpack-plugin@5.5.0
yarn list --depth 0 --pattern webpack
yarn list v1.13.0
β”œβ”€ @svgr/webpack@4.1.0
β”œβ”€ babel-plugin-smart-webpack-import@1.4.2
β”œβ”€ copy-webpack-plugin@4.6.0
β”œβ”€ error-overlay-webpack-plugin@0.1.6
β”œβ”€ extract-css-chunks-webpack-plugin@3.3.2
β”œβ”€ friendly-errors-webpack-plugin@1.7.0
β”œβ”€ last-call-webpack-plugin@3.0.0
β”œβ”€ lodash-webpack-plugin@0.11.5
β”œβ”€ optimize-css-assets-webpack-plugin@5.0.1
β”œβ”€ robotstxt-webpack-plugin@5.0.0
β”œβ”€ stats-webpack-plugin@0.7.0
β”œβ”€ terser-webpack-plugin@1.2.2
β”œβ”€ webpack-bundle-analyzer@3.0.3
β”œβ”€ webpack-cli@3.2.3
β”œβ”€ webpack-dev-middleware@3.5.2
β”œβ”€ webpack-hot-middleware@2.24.3
β”œβ”€ webpack-hot-server-middleware@0.5.0
β”œβ”€ webpack-log@2.0.0
β”œβ”€ webpack-sources@1.3.0
β”œβ”€ webpack@4.29.3
└─ webpackbar@3.1.5

To Reproduce

Steps to reproduce the behavior:

I am not sure. Seems to be related to SSR, Webpack and Loadable.

Expected behavior

That the error/warning is gone.

Link to repl or repo (highly encouraged)

Please provide a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 10.14.3
 - CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
 - Memory: 988.22 MB / 16.00 GB
 - Shell: 5.3 - /bin/zsh
## Binaries:
 - Node: 11.9.0 - /usr/local/bin/node
 - Yarn: 1.13.0 - ~/Workspace/witt/emma-boilerplate/node_modules/.bin/yarn
 - npm: 6.7.0 - /usr/local/bin/npm
## npmPackages:
 - @loadable/babel-plugin: 5.6.0 => 5.6.0
 - @loadable/component: 5.6.0 => 5.6.0
 - @loadable/server: 5.6.0 => 5.6.0
 - @loadable/webpack-plugin: 5.5.0 => 5.5.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
swernerxcommented, Feb 12, 2019

It seems like going back to return eval('module.require')(modulePath) in the last line fixes the issue for me.

0reactions
gregbergecommented, Feb 15, 2019

@swernerx OK sorry, I got it, yeah we need to change it to eval.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack reports "the request of a dependency is an ... - GitHub
Bug Report Webpack v4 reports the following issue when executed: ... request of a dependency is an expression" (SSR, Server-Side only) #234.
Read more >
webpack the request of a dependency is an expression
Seems to be related to SSR, Webpack and Loadable. Expected behavior. That the error/warning is gone. Link to repl or repo (highly encouraged)....
Read more >
Webpack - Critical dependency: the request of a dependency ...
Webpack tries to resolve require calls statically to make a minimal bundle. When a library uses variables or expressions in a require call...
Read more >
How to Enable Server-Side Rendering for a React App
In this tutorial, you will initialize a React app using Create React App and then modify the project to enable server-side rendering.
Read more >
Server-Side Rendering from zero to hero - DEV Community ‍ ‍
Let's move the application to SSR! Β· Step 1. Install dependencies Β· Step 2. Configuring webpack.config.js Β· Step 3. Modification of the code....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found