Skip to content

webpackIgnore: true is ignored, dynamic import/require still processed #11311

Closed

Description

@petermetz

Bug report

What is the current behavior?

Dynamic require gets parsed that isn't supposed to because I marked it with the webpackIgnore: true comment based on what I see here: https://github.com/webpack/webpack/pull/7034/files

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

webpack.config.js

module.exports = {
  entry: {
    "x.bundle.js": `./x.js`,
  },
  target: "node",
  mode: "development",
  devtool: "inline-source-map",
  resolve: {
    extensions: [".js"],
  },
  output: {
    filename: "[name]",
  },
};

x.js

const packageName = "net"
const x = require(/* webpackIgnore: true */ packageName);

x.bundle.js

/***/ "./x.js":
/*!**************!*\
  !*** ./x.js ***!
  \**************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

const packageName = "net"
const x = __webpack_require__("./ sync recursive")(packageName);

/***/ })

What is the expected behavior?

x.bundle.js should look like this (e.g. no dynamic require parsing due to the ignore comment) so that it doesn't crash when the module is available to be loaded by NodeJS.

/***/ "./x.js":
/*!**************!*\
  !*** ./x.js ***!
  \**************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

const packageName = "net"
const x = require(packageName);

/***/ })

Other relevant information:
webpack version: 4.44.1
Node.js version: v12.16.3
Operating System: Ubuntu 20.04
Additional tools:

Activity

  1. alexander-akait commented on Aug 12, 2020

    @alexander-akait
    Member

    Please create reproducible test repo, maybe babel/typescript remove comments

  2. petermetz commented on Aug 12, 2020

    @petermetz
    ContributorAuthor

    Please create reproducible test repo, maybe babel/typescript remove comments

    @evilebottnawi Thank you for the response!

    Repo: https://github.com/petermetz/webpack-11311

  3. alexander-akait commented on Aug 12, 2020

    @alexander-akait
    Member
  4. petermetz commented on Aug 12, 2020

    @petermetz
    ContributorAuthor

    @petermetz 404

    @evilebottnawi Oops, try now please. Set the visibility to public just now.

  5. sokra commented on Aug 12, 2020

    @sokra
    Member

    webpackIgnore is only for import() not for require

  6. petermetz commented on Aug 12, 2020

    @petermetz
    ContributorAuthor

    webpackIgnore is only for import() not for require

    @sokra Ohh, maybe turn this into a feature request then? I need the webpackIgnore to work for require because ts-loader compiles the import down to require (need the commonjs module resolution because it's a NodeJS project).

  7. sokra commented on Aug 12, 2020

    @sokra
    Member

    Send a PR to add magic comments for require(). There are more possible comments that could apply here:
    webpackExports, webpackInclude, webpackExclude, webpackIgnore

  8. added
    help wanted
    on Aug 12, 2020
  9. petermetz commented on Aug 12, 2020

    @petermetz
    ContributorAuthor

    Send a PR to add magic comments for require(). There are more possible comments that could apply here:
    webpackExports, webpackInclude, webpackExclude, webpackIgnore

    @sokra Here's the PR #11316
    Only added webpackIgnore because that's the one I need and fully understand, never needed or used the other ones.

  10. webpack-bot commented on Nov 12, 2020

    @webpack-bot
    Contributor

    This issue had no activity for at least three months.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  11. added
    status: stale
    on Nov 12, 2020
  12. alexander-akait commented on Nov 13, 2020

    @alexander-akait
    Member

    bump

  13. removed
    status: stale
    on Nov 13, 2020
  14. kolserdav commented on Sep 10, 2024

    @kolserdav

    It only works for --mode=development, in production it doesn't work for me.

  15. petermetz commented on Sep 10, 2024

    @petermetz
    ContributorAuthor

    @kolserdav Do you mean the webpackIgnore magic comment or something else? If yes, can you please create a simplified test repo where the issue can be observed?

  16. kolserdav commented on Sep 11, 2024

    @kolserdav

    Hi, @petermetz. Thank you for your reply! Actually I see now that it works fine. My issue were connected with my code delivery. I use the bundle in my Next.js application and it make bundle with webpack but the bundle in production mode have no comments and so it's producing a wrong result.

  17. petermetz commented on Sep 11, 2024

    @petermetz
    ContributorAuthor

    @kolserdav You are most welcome! Glad it all worked out in the end!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions