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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWC helper functions are not bundled into output #8406

Closed
Enet4 opened this issue Aug 19, 2022 · 1 comment
Closed

SWC helper functions are not bundled into output #8406

Enet4 opened this issue Aug 19, 2022 · 1 comment

Comments

@Enet4
Copy link

Enet4 commented Aug 19, 2022

馃悰 bug report

With the sample project below, SWC is injecting imports for a shim function in order to provide public class fields to more browsers, but they are not being bundled into the output.

馃帥 Configuration (package.json)

{
  "main": "out.js",
  "source": "src/index.js",
  "files": [
    "out.js"
  ],
  "scripts": {
    "build": "parcel build --no-source-maps",
    "build-debug": "parcel build --no-optimize"
  },
  "targets": {
    "main": {
      "context": "browser",
      "outputFormat": "commonjs",
      "isLibrary": false,
      "optimize": true,
      "includeNodeModules": true,
      "engines": {
        "browsers": "> 0.5%, last 2 versions, not dead"
      }
    }
  }
}

馃 Expected Behavior

The output file out.js should incorporate any helper functions that SWC chooses to include for browser compatibility, since I explicitly requested Parcel to include all node modules via includeNodeModules.

馃槸 Current Behavior

With the current browserslist, swc fetches the helper function @swc/helpers/lib/_define_property.js, but it is treated as an external module.

馃拋 Possible Solution

This might be heavily related with the bug reported in #8401. The example above also reproduces it. The difference is that I do not expect any imports nor requires in the output.

馃敠 Context

I am building a commonjs module which is expected to be consumed by a browser after some post-processing (i.e. module bundling done at run-time). Any attempt at calling require or import in the output is undesirable. In this use case the main expectation is for Parcel to bundle any helper functions that SWC introduces for whichever reason.

馃捇 Code Sample

src/index.js:

export default class Foo {
    seqNumber = 0;
}

馃實 Your Environment

Software Version(s)
Parcel 2.7.0
Node 16.16.0
npm/Yarn npm 8.11.0
Operating System Windows 11
@github-actions github-actions bot added the Stale Inactive issues label Feb 16, 2023
@Enet4
Copy link
Author

Enet4 commented Feb 16, 2023

All right, the bug was gone after updating all dependencies in the example above. It may have been resolved by #8693.

@Enet4 Enet4 closed this as completed Feb 16, 2023
@github-actions github-actions bot removed the Stale Inactive issues label Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant