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

bug: swc external helper breaking webpack's dependency resolution in next 15 #72911

Open
rishabh3112 opened this issue Nov 18, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js.

Comments

@rishabh3112
Copy link

rishabh3112 commented Nov 18, 2024

Link to the code that reproduces this issue

https://github.com/rishabh3112/next-15-swc-external-helpers-bug

To Reproduce

  1. Clone reproduction repo
  2. npm install
  3. npm run dev

Current vs. Expected behavior

It should work as it was working in next 14.

Current: After webpack parsing with external helper (Next 15):

__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _swc_helpers_type_of__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @swc/helpers/_/_type_of */ "./node_modules/@swc/helpers/esm/_type_of.js");

(function(root, factory) {
    if (typeof define === "function" && __webpack_require__.amdO) {
        define([
            "exports"
        ], function(exports1) {
            root.Backbone = factory(root, exports1);
        });
    } else if (typeof exports !== "undefined") {
        factory(root, exports);
    } else {
        root.Backbone = factory(root, {});
    }
})(window, function(root, Backbone) {
    // Removed actual backbone code for minimal reproduction
    Backbone.Modal = function() {
        var something = root.something;
        // So that _type_of swc helper import gets added to the code
        if ((typeof something === "undefined" ? "undefined" : (0,_swc_helpers_type_of__WEBPACK_IMPORTED_MODULE_0__._)(something)) === "object") {
            return "object";
        }
        return "don't know";
    };
    return Backbone;
});

SWC playground link: link

Expected: After webpack parsing without external helper (Next 14):

var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(root, factory) {
    if (true) {
        !(__WEBPACK_AMD_DEFINE_ARRAY__ = [
            exports
        ], __WEBPACK_AMD_DEFINE_RESULT__ = (function(exports1) {
            root.Backbone = factory(root, exports1);
        }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
		__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
    } else {}
})(window, function(root, Backbone) {
    // Removed actual backbone code for minimal reproduction
    Backbone.Modal = function() {
        var something = root.something;
        // So that _type_of swc helper import gets added to the code
        if (typeof something === "object") {
            return "object";
        }
        return "don't know";
    };
    return Backbone;
});

SWC playground link: link

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.6.0: Wed Apr 24 06:05:14 PDT 2024; root:xnu-8020.240.18.708.4~1/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: 1.22.22
  pnpm: 9.12.2
Relevant Packages:
  next: 15.0.3 // Latest available version is detected (15.0.3).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC, Webpack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Other (Deployed)

Additional context

It should work like it was working in next 14.
Willing to contribute.

@rishabh3112 rishabh3112 added the bug Issue was opened via the bug report template. label Nov 18, 2024
@github-actions github-actions bot added SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js. labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant