Skip to content

Critical dependency warning on a require.resolve #1099

Closed

Description

@webpack-bot

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Critical dependency warning on require.resolve call.

If the current behavior is a bug, please provide the steps to reproduce.

Create a file with following contents and process it with default webpack config:

let resolvedPath = require.resolve(`${somepath}`);

What is the expected behavior?

No warnings expected due to this is not a require statement and no external modules are loaded.

If this is a feature request, what is motivation or use case for changing the behavior?

–

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

macOS 10.12.4 (16E195)
nodeJS v7.7.2
webpack v2.3.3


This issue was moved from webpack/webpack#4681 by @sokra. Orginal issue was by @dkfiresky.

Document behavior for dynamic expressions.

webpack is a static bundler and requires statically analysable expressions.

Activity

  1. skipjack commented on Apr 11, 2017

    @skipjack
    Contributor

    This seems related to #1083. If I understand correctly, webpack can't import(...) or require a pure variable e.g. import(varName) because there's no way to determine what group of files are being referred to. However, something like:

    import('./directory/${varName}.css')

    gives webpack enough information to go bundle all css files from ./directory and make them accessible as require-able modules when the variable is actually defined. @webpack/documentation-team is this correct?

  2. bebraw commented on Apr 11, 2017

    @bebraw
    Contributor

    My understanding is that import('./directory/${varName}.css') sets up a require.context internally. If you had import(varName), how could you tell statically where to point in the file system?

  3. simon04 commented on Apr 19, 2017

    @simon04
    Contributor

    With #1110 merged, is there anything left to be done?

  4. skipjack commented on Apr 27, 2017

    @skipjack
    Contributor

    @dkfiresky based on the old docs, it seems require.resolve does not behave exactly like require and instead returns the id for that module. However, after a quick search, I couldn't find anything in the new docs analogous to the page I just linked to. I'm not too familiar with require.resolve in webpack so we'd have to check with the rest of @webpack/documentation-team, but it seems maybe we should add a similar page in the new /content/api section?

    I'd be happy to try to port this page over if someone gives me some pointers on what is and isn't still relevant.

  5. self-assigned this
    on May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions