Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
swernerx opened this issue Feb 12, 2019 · 8 comments

Comments

@swernerx
Copy link

🐛 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
@swernerx swernerx changed the title Webpack reports Webpack reports "the request of a dependency is an expression" Feb 12, 2019
@swernerx
Copy link
Author

I am trying to reduce the code in our SSR "branch" right now. I figured when I remove the following import: import { ChunkExtractor } from '@loadable/server' the issue is gone.

@swernerx swernerx changed the title Webpack reports "the request of a dependency is an expression" Webpack reports "the request of a dependency is an expression" (SSR, Server-Side only) Feb 12, 2019
@swernerx
Copy link
Author

The error is server-side only and is gone when removing the ChunkExtractor import.

Probably the issue is somehow related to: #181

@swernerx
Copy link
Author

Please note: We bundle all app-code on client+server with Webpack. The only excluded package right now is node-fetch.

@swernerx
Copy link
Author

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

@gregberge
Copy link
Owner

I think your issue is a webpack one, you do: import(dynamicPath). It is not supported by webpack. Please restrict your path using an interpolated string import(``./some/${page}``)

@swernerx
Copy link
Author

Actually your assumption is not true. We do not use a single dynamic import. All static imports based on plain strings. So closing this report might be a little too early.

@swernerx
Copy link
Author

The Webpack reporting is true as it seems. It mentions the problem inside the loadable code. As I tried to explain: changing back the require code to eval fixes the issue for us.

@gregberge gregberge reopened this Feb 15, 2019
@gregberge
Copy link
Owner

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

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants